Toby Chui 3 недель назад
Родитель
Сommit
87b64a1fb0

BIN
src/web/PDF Tool/img/desktop_icon.png


BIN
src/web/PDF Tool/img/desktop_icon.psd


BIN
src/web/PDF Tool/img/module_icon.png


+ 0 - 39
src/web/PDF Tool/img/module_icon.svg

@@ -1,39 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
-  <defs>
-    <linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
-      <stop offset="0%" stop-color="#5B9CF6"/>
-      <stop offset="100%" stop-color="#2563EB"/>
-    </linearGradient>
-    <linearGradient id="doc" x1="0" y1="0" x2="0" y2="1">
-      <stop offset="0%" stop-color="#FFFFFF"/>
-      <stop offset="100%" stop-color="#F0F4FF"/>
-    </linearGradient>
-  </defs>
-  <!-- App background -->
-  <rect width="128" height="128" rx="24" fill="url(#bg)"/>
-  <!-- Document shadow -->
-  <rect x="20" y="16" width="64" height="82" rx="6" fill="rgba(0,0,0,0.15)" transform="translate(2,2)"/>
-  <!-- Document body -->
-  <rect x="20" y="16" width="64" height="82" rx="6" fill="url(#doc)"/>
-  <!-- Page fold triangle -->
-  <path d="M64 16 L84 16 L84 36 Z" fill="#DBEAFE"/>
-  <path d="M64 16 L64 36 L84 36" fill="none" stroke="#93C5FD" stroke-width="1"/>
-  <!-- Document lines -->
-  <rect x="28" y="46" width="46" height="4" rx="2" fill="#94A3B8"/>
-  <rect x="28" y="55" width="38" height="4" rx="2" fill="#94A3B8" opacity="0.7"/>
-  <rect x="28" y="64" width="42" height="4" rx="2" fill="#94A3B8" opacity="0.6"/>
-  <rect x="28" y="73" width="28" height="4" rx="2" fill="#94A3B8" opacity="0.5"/>
-  <!-- Magnifying glass handle -->
-  <line x1="88" y1="90" x2="110" y2="112" stroke="#F97316" stroke-width="9" stroke-linecap="round"/>
-  <!-- Magnifying glass circle - shadow -->
-  <circle cx="77" cy="79" r="24" fill="rgba(0,0,0,0.18)" transform="translate(1,1)"/>
-  <!-- Magnifying glass circle -->
-  <circle cx="77" cy="79" r="24" fill="white" opacity="0.95"/>
-  <circle cx="77" cy="79" r="18" fill="#EFF6FF"/>
-  <!-- Magnifying glass inner icon - lines representing content -->
-  <rect x="68" y="72" width="18" height="2.5" rx="1.25" fill="#60A5FA" opacity="0.9"/>
-  <rect x="68" y="77" width="14" height="2.5" rx="1.25" fill="#60A5FA" opacity="0.7"/>
-  <rect x="68" y="82" width="16" height="2.5" rx="1.25" fill="#60A5FA" opacity="0.6"/>
-  <!-- Magnifying glass rim -->
-  <circle cx="77" cy="79" r="24" fill="none" stroke="#F97316" stroke-width="4.5"/>
-</svg>

+ 0 - 488
src/web/PDF Tool/index.html

@@ -1,488 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1">
-    <title>PDF Tool</title>
-    <link rel="icon" type="image/svg+xml" href="img/module_icon.svg">
-    <script src="../script/jquery.min.js"></script>
-    <script src="../script/ao_module.js"></script>
-    <style>
-        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
-
-        :root {
-            --bg: #F2F2F7;
-            --sidebar-bg: #EFEFF4;
-            --text: #1C1C1E;
-            --sub: #6B6B70;
-            --accent: #007AFF;
-            --card-bg: #FFFFFF;
-            --border: #D1D1D6;
-            --inp-bg: #FFFFFF;
-            --progress-bg: #E5E5EA;
-            --danger: #FF3B30;
-        }
-
-        @media (prefers-color-scheme: dark) {
-            :root {
-                --bg: #1C1C1E; --sidebar-bg: #2C2C2E; --text: #F2F2F7; --sub: #8E8E93;
-                --card-bg: #2C2C2E; --border: #48484A; --inp-bg: #3A3A3C;
-                --progress-bg: #3A3A3C; --accent: #0A84FF;
-            }
-        }
-
-        /* ArozOS system theme override (wins over the media query) */
-        html[data-theme="dark"] {
-            --bg: #1C1C1E; --sidebar-bg: #2C2C2E; --text: #F2F2F7; --sub: #8E8E93;
-            --card-bg: #2C2C2E; --border: #48484A; --inp-bg: #3A3A3C;
-            --progress-bg: #3A3A3C; --accent: #0A84FF;
-        }
-        html[data-theme="light"] {
-            --bg: #F2F2F7; --sidebar-bg: #EFEFF4; --text: #1C1C1E; --sub: #6B6B70;
-            --card-bg: #FFFFFF; --border: #D1D1D6; --inp-bg: #FFFFFF;
-            --progress-bg: #E5E5EA; --accent: #007AFF;
-        }
-
-        html, body {
-            width: 100%; height: 100%; overflow: hidden;
-            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
-            background: var(--bg); color: var(--text);
-        }
-
-        /* ── App shell ──────────────────────────────────────────────── */
-        .pe-root {
-            position: relative;
-            display: flex; flex-direction: column;
-            width: 100%; height: 100%;
-            overflow: hidden;
-        }
-
-        .pe-toolbar {
-            display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
-            padding: 8px 12px;
-            border-bottom: 1px solid var(--border);
-            background: var(--card-bg);
-            flex-shrink: 0;
-        }
-        .pe-sep { width: 1px; height: 20px; background: var(--border); margin: 0 3px; }
-        .pe-spacer { flex: 1; }
-        .pe-fname {
-            font-size: 12px; color: var(--sub);
-            max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
-        }
-
-        .pe-tbtn {
-            display: inline-flex; align-items: center; gap: 5px;
-            padding: 6px 10px; border-radius: 7px;
-            border: 1px solid var(--border); background: var(--card-bg);
-            color: var(--text); font-size: 12.5px; font-weight: 600;
-            font-family: inherit; cursor: pointer;
-        }
-        .pe-tbtn:hover { background: rgba(0,0,0,0.05); }
-        .pe-tbtn:disabled { opacity: 0.4; cursor: default; }
-        .pe-tbtn:disabled:hover { background: var(--card-bg); }
-        .pe-tbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
-        .pe-tbtn.primary:hover { opacity: 0.9; background: var(--accent); }
-        .pe-tbtn.primary:disabled:hover { background: var(--accent); }
-
-        .pe-iconbtn {
-            width: 28px; height: 28px; border-radius: 6px;
-            border: 1px solid var(--border); background: var(--card-bg);
-            color: var(--text); cursor: pointer;
-            display: inline-flex; align-items: center; justify-content: center;
-        }
-        .pe-iconbtn:hover { background: rgba(0,0,0,0.05); }
-        .pe-iconbtn:disabled { opacity: 0.4; cursor: default; }
-
-        .pe-page-lbl { font-size: 12px; color: var(--sub); min-width: 70px; text-align: center; }
-        .pe-zoom {
-            font-size: 12.5px; padding: 5px 6px; border-radius: 7px;
-            border: 1px solid var(--border); background: var(--card-bg);
-            color: var(--text); font-family: inherit; cursor: pointer;
-        }
-        .pe-zoom:disabled { opacity: 0.4; cursor: default; }
-
-        /* ── Stage: Fit sizes the page so it never needs scrolling ──── */
-        .pe-stage {
-            position: relative; flex: 1; min-height: 0;
-            display: flex; overflow: hidden;
-            background: var(--progress-bg);
-        }
-        .pe-stage.zoomed { overflow: auto; }
-        .pe-stage.dragover::after {
-            content: 'Drop a PDF here';
-            position: absolute; inset: 10px; z-index: 20;
-            border: 2px dashed var(--accent); border-radius: 12px;
-            background: rgba(0,122,255,0.09);
-            display: flex; align-items: center; justify-content: center;
-            font-size: 15px; font-weight: 600; color: var(--accent);
-            pointer-events: none;
-        }
-        .pe-empty {
-            margin: auto; text-align: center; color: var(--sub);
-            font-size: 13.5px; line-height: 1.6; padding: 20px;
-        }
-
-        .pe-wrap { margin: auto; position: relative; box-shadow: 0 4px 18px rgba(0,0,0,0.22); flex-shrink: 0; }
-        .pe-wrap canvas { display: block; }
-        .pe-overlay { position: absolute; inset: 0; }
-
-        .pe-ov { position: absolute; box-sizing: border-box; cursor: move; border: 1px solid transparent; }
-        .pe-ov.selected { border-color: var(--accent); }
-        .pe-ov.pe-text {
-            padding: 1px 2px; white-space: pre; line-height: 1.25;
-            font-family: 'Helvetica Neue', Arial, sans-serif; outline: none; min-width: 12px;
-        }
-        .pe-ov.pe-text[contenteditable="true"] { cursor: text; background: rgba(0,122,255,0.06); white-space: pre-wrap; }
-        .pe-ov.pe-img img { display: block; width: 100%; height: 100%; pointer-events: none; -webkit-user-drag: none; }
-
-        .pe-handle {
-            position: absolute; right: -6px; bottom: -6px;
-            width: 13px; height: 13px; border-radius: 50%;
-            background: var(--accent); border: 2px solid #fff;
-            cursor: nwse-resize; display: none;
-        }
-        .pe-ov.selected .pe-handle { display: block; }
-        .pe-del {
-            position: absolute; right: -9px; top: -9px;
-            width: 18px; height: 18px; border-radius: 50%;
-            background: var(--danger); color: #fff; border: 2px solid #fff;
-            cursor: pointer; display: none; align-items: center; justify-content: center; padding: 0;
-        }
-        .pe-ov.selected .pe-del { display: flex; }
-
-        /* ── Floating text property bar ─────────────────────────────── */
-        .pe-props {
-            position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
-            z-index: 30; display: none; align-items: center; gap: 16px;
-            padding: 8px 14px; background: var(--card-bg);
-            border: 1px solid var(--border); border-radius: 10px;
-            box-shadow: 0 6px 22px rgba(0,0,0,0.18);
-        }
-        .pe-props.show { display: flex; }
-        .pe-props label { font-size: 12px; color: var(--sub); display: flex; align-items: center; gap: 7px; }
-        .pe-props input[type=color] {
-            width: 30px; height: 26px; border: 1px solid var(--border);
-            border-radius: 6px; background: none; cursor: pointer; padding: 0;
-        }
-        .pe-props input[type=range] { accent-color: var(--accent); }
-
-        /* ── Toast: pill at the bottom centre, fades itself out ─────── */
-        .pe-toast {
-            position: absolute; bottom: 18px; left: 50%;
-            transform: translateX(-50%) translateY(10px);
-            z-index: 60; max-width: 86%;
-            opacity: 0; pointer-events: none;
-            transition: opacity 0.18s ease, transform 0.18s ease;
-        }
-        .pe-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
-        /* lift clear of the text property bar when it is showing */
-        .pe-root.props-open .pe-toast { bottom: 76px; }
-
-        .pe-pill {
-            display: block; padding: 9px 18px; border-radius: 999px;
-            background: rgba(28,28,30,0.94); color: #fff;
-            font-size: 13px; line-height: 1.35;
-            box-shadow: 0 6px 24px rgba(0,0,0,0.34);
-            max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
-        }
-        .pe-pill.err { background: rgba(199,42,36,0.96); }
-        .pe-pill strong { font-weight: 700; }
-
-        /* ── Dropdown menu ──────────────────────────────────────────── */
-        .pe-menu {
-            position: absolute; z-index: 70; min-width: 212px;
-            background: var(--card-bg); border: 1px solid var(--border);
-            border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,0.22);
-            padding: 5px;
-        }
-        .pe-menu-item {
-            display: flex; align-items: center; gap: 9px; width: 100%;
-            padding: 8px 10px; border: none; background: none; border-radius: 7px;
-            color: var(--text); font-size: 13px; font-family: inherit;
-            text-align: left; cursor: pointer;
-        }
-        .pe-menu-item:hover:not(:disabled) { background: rgba(128,128,128,0.2); }
-        .pe-menu-item:disabled { opacity: 0.4; cursor: default; }
-        .pe-menu-ico {
-            width: 15px; flex-shrink: 0; color: var(--sub);
-            display: inline-flex; align-items: center; justify-content: center;
-        }
-        .pe-menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }
-
-        /* ── Split button (Save + caret) ────────────────────────────── */
-        .pe-split { display: inline-flex; }
-        .pe-split .pe-tbtn:first-child {
-            border-top-right-radius: 0; border-bottom-right-radius: 0;
-        }
-        .pe-split .pe-tbtn:last-child {
-            border-top-left-radius: 0; border-bottom-left-radius: 0;
-            border-left: 1px solid rgba(255,255,255,0.32);
-            padding-left: 7px; padding-right: 7px;
-        }
-
-        .result-box { padding: 11px 14px; border-radius: 10px; font-size: 13px; line-height: 1.5; margin-top: 10px; }
-        .result-ok { background: rgba(48,176,110,0.12); border: 1px solid rgba(48,176,110,0.28); color: #1B7A43; }
-        .result-err { background: rgba(255,59,48,0.1); border: 1px solid rgba(255,59,48,0.25); color: #C0392B; }
-        @media (prefers-color-scheme: dark) {
-            .result-ok { color: #4ADE80; }
-            .result-err { color: #FF6B6B; }
-        }
-        html[data-theme="dark"] .result-ok { color: #4ADE80; }
-        html[data-theme="dark"] .result-err { color: #FF6B6B; }
-
-        /* ── Stamp menu ─────────────────────────────────────────────── */
-        .pe-stamp-menu {
-            position: absolute; z-index: 50;
-            background: var(--card-bg); border: 1px solid var(--border);
-            border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,0.18);
-            padding: 10px; width: 236px; max-height: 300px; overflow-y: auto; display: none;
-        }
-        .pe-stamp-menu.show { display: block; }
-        .pe-stamp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
-        .pe-stamp-item {
-            border: 1px solid var(--border); border-radius: 7px; padding: 6px; cursor: pointer;
-            display: flex; flex-direction: column; gap: 4px; align-items: center;
-            background: repeating-conic-gradient(#0000000d 0% 25%, transparent 0% 50%) 50% / 14px 14px;
-        }
-        .pe-stamp-item:hover { border-color: var(--accent); }
-        .pe-stamp-item img { max-width: 100%; height: 54px; object-fit: contain; }
-        .pe-stamp-item span {
-            font-size: 11px; color: var(--text); max-width: 100%;
-            overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
-        }
-        .pe-stamp-empty { font-size: 12px; color: var(--sub); text-align: center; padding: 12px 6px; line-height: 1.5; }
-
-        /* ── Modal ──────────────────────────────────────────────────── */
-        .pt-modal-back {
-            position: fixed; inset: 0; z-index: 900;
-            background: rgba(0,0,0,0.42);
-            display: flex; align-items: center; justify-content: center;
-            padding: 24px;
-        }
-        .pt-modal {
-            background: var(--bg); color: var(--text);
-            border: 1px solid var(--border); border-radius: 14px;
-            box-shadow: 0 18px 48px rgba(0,0,0,0.32);
-            width: 100%; max-width: 480px; max-height: 100%;
-            display: flex; flex-direction: column; overflow: hidden;
-        }
-        .pt-modal-hd {
-            display: flex; align-items: center; justify-content: space-between;
-            padding: 13px 16px; border-bottom: 1px solid var(--border);
-            background: var(--card-bg); flex-shrink: 0;
-        }
-        .pt-modal-hd span { font-size: 14px; font-weight: 700; }
-        .pt-modal-x {
-            border: none; background: none; color: var(--sub); cursor: pointer;
-            width: 26px; height: 26px; border-radius: 6px;
-            display: inline-flex; align-items: center; justify-content: center;
-        }
-        .pt-modal-x:hover { background: rgba(0,0,0,0.07); color: var(--text); }
-        .pt-modal-bd { padding: 16px; overflow-y: auto; flex: 1; }
-        .pt-modal-ft {
-            display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
-            padding: 11px 16px; border-top: 1px solid var(--border);
-            background: var(--card-bg); flex-shrink: 0;
-        }
-
-        /* ── Form controls used inside dialogs ──────────────────────── */
-        .pt-btn {
-            padding: 7px 14px; border-radius: 8px;
-            border: 1px solid var(--border); background: var(--card-bg);
-            color: var(--text); font-size: 13px; font-weight: 600;
-            font-family: inherit; cursor: pointer;
-        }
-        .pt-btn:hover { background: rgba(0,0,0,0.05); }
-        .pt-btn:disabled { opacity: 0.45; cursor: default; }
-        .pt-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
-        .pt-btn.primary:hover { opacity: 0.9; }
-        .pt-btn.tiny { padding: 4px 9px; font-size: 12px; }
-
-        .pt-iconbtn {
-            border: none; background: none; cursor: pointer;
-            padding: 4px; border-radius: 5px; color: var(--sub);
-            display: inline-flex; align-items: center; justify-content: center;
-        }
-        .pt-iconbtn:hover { background: rgba(0,0,0,0.07); color: var(--text); }
-        .pt-iconbtn.danger:hover { color: var(--danger); background: rgba(255,59,48,0.1); }
-
-        .pt-field { margin-bottom: 15px; }
-        .pt-label {
-            display: block; font-size: 11px; font-weight: 700; color: var(--sub);
-            text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;
-        }
-        .pt-hint { font-size: 12.5px; color: var(--sub); line-height: 1.5; margin-bottom: 10px; }
-        .pt-row { display: flex; align-items: center; gap: 9px; }
-        .pt-path { font-size: 12.5px; color: var(--sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
-        .pt-radios { display: flex; gap: 14px; }
-        .pt-radios label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
-        .pt-radios input { accent-color: var(--accent); cursor: pointer; }
-        .pt-field input[type=range] { accent-color: var(--accent); }
-
-        .pt-input, .pt-select {
-            width: 100%; padding: 8px 10px;
-            background: var(--inp-bg); border: 1px solid var(--border);
-            border-radius: 8px; font-size: 13px; color: var(--text);
-            font-family: inherit; outline: none;
-        }
-        .pt-input:focus, .pt-select:focus { border-color: var(--accent); }
-
-        .pt-empty-box {
-            padding: 20px 16px; text-align: center;
-            font-size: 12.5px; color: var(--sub);
-            border: 1.5px dashed var(--border); border-radius: 10px;
-        }
-
-        .pt-pathbox {
-            padding: 9px 11px; border-radius: 8px;
-            background: var(--inp-bg); border: 1px solid var(--border);
-            font-size: 12.5px; color: var(--text); word-break: break-all;
-            font-family: 'SF Mono', Consolas, monospace;
-        }
-
-        /* ── Chop grid ──────────────────────────────────────────────── */
-        .chop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 11px; }
-        .chop-card {
-            background: var(--card-bg); border: 1px solid var(--border);
-            border-radius: 10px; padding: 9px;
-            display: flex; flex-direction: column; gap: 7px;
-        }
-        .chop-thumb {
-            width: 100%; height: 84px; border-radius: 7px;
-            background: repeating-conic-gradient(#0000000d 0% 25%, transparent 0% 50%) 50% / 16px 16px;
-            display: flex; align-items: center; justify-content: center; overflow: hidden;
-        }
-        .chop-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
-        .chop-name { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
-        .chop-card-btns { display: flex; gap: 4px; align-items: center; }
-        .chop-card-btns .pt-btn { flex: 1; }
-
-        /* ── Image list (Create PDF from images) ────────────────────── */
-        .pt-imglist { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
-        .pt-imgrow {
-            display: flex; align-items: center; gap: 10px;
-            padding: 7px 10px; border-bottom: 1px solid var(--border);
-            background: var(--card-bg);
-        }
-        .pt-imgrow:last-child { border-bottom: none; }
-        .pt-thumb {
-            width: 34px; height: 34px; border-radius: 5px;
-            object-fit: cover; background: var(--progress-bg); flex-shrink: 0;
-        }
-        .pt-imgname { flex: 1; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
-        .pt-imgbtns { display: flex; gap: 2px; }
-    </style>
-</head>
-<body>
-
-<div class="pe-root" id="peRoot">
-    <div class="pe-toolbar">
-        <button class="pe-tbtn primary" id="peOpen" title="Open a document">
-            <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
-                <path d="M1.2 3.2h3.4l1.3 1.6h6.9v6.4H1.2z"/><path d="M1.2 6h11.6"/>
-            </svg> Open
-            <svg width="9" height="9" viewBox="0 0 10 10" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3.8 L5 6.6 L8 3.8"/></svg>
-        </button>
-        <span class="pe-fname" id="peFileName"></span>
-
-        <div class="pe-sep"></div>
-
-        <button class="pe-iconbtn" id="peAddText" title="Insert a text box" aria-label="Insert a text box" disabled>
-            <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round">
-                <path d="M2 3.2V2h10v1.2M7 2v10M5 12h4"/>
-            </svg>
-        </button>
-        <button class="pe-iconbtn" id="peAddImg" title="Insert an image from the server" aria-label="Insert an image from the server" disabled>
-            <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
-                <rect x="1.5" y="2.5" width="11" height="9" rx="1.3"/><circle cx="4.7" cy="5.5" r="1"/>
-                <path d="M1.5 10 L5 6.5 L7.5 8.5 L10 5.5 L12.5 9"/>
-            </svg>
-        </button>
-        <button class="pe-iconbtn" id="peUpload" title="Insert an image from this device" aria-label="Insert an image from this device" disabled>
-            <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
-                <path d="M7 9V2.5M4.3 5.2 7 2.5l2.7 2.7"/><path d="M2 9.5v1.5a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V9.5"/>
-            </svg>
-        </button>
-        <button class="pe-iconbtn" id="peAddStamp" title="Place a saved company chop" aria-label="Place a saved company chop" disabled>
-            <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
-                <path d="M7 1.5c-1.7 0-2.6 1.3-2.2 2.9.2.9.4 1.6-.3 2.1H9.5c-.7-.5-.5-1.2-.3-2.1C9.6 2.8 8.7 1.5 7 1.5Z"/>
-                <rect x="2.5" y="8.5" width="9" height="1.8" rx="0.6"/><line x1="1.8" y1="12.2" x2="12.2" y2="12.2"/>
-            </svg>
-        </button>
-
-        <div class="pe-sep"></div>
-
-        <button class="pe-iconbtn" id="pePrev" title="Previous page" aria-label="Previous page" disabled>
-            <svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8.5 2 L4 6.5 L8.5 11"/></svg>
-        </button>
-        <span class="pe-page-lbl" id="pePageLbl">—</span>
-        <button class="pe-iconbtn" id="peNext" title="Next page" aria-label="Next page" disabled>
-            <svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 2 L9 6.5 L4.5 11"/></svg>
-        </button>
-
-        <div class="pe-sep"></div>
-
-        <select class="pe-zoom" id="peZoom" title="Zoom" disabled>
-            <option value="fit" selected>Fit</option>
-            <option value="0.5">50%</option>
-            <option value="0.75">75%</option>
-            <option value="1">100%</option>
-            <option value="1.25">125%</option>
-            <option value="1.5">150%</option>
-            <option value="2">200%</option>
-        </select>
-
-        <div class="pe-spacer"></div>
-
-        <span class="pe-split">
-            <button class="pe-tbtn primary" id="peSave" title="Save the edited PDF" disabled>
-                <svg width="13" height="13" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
-                    <path d="M2 2h7.5L12 4.5V12H2z"/><path d="M4.5 2v3h4V2"/><rect x="4.5" y="7.5" width="5" height="3.5"/>
-                </svg> Save
-            </button>
-            <button class="pe-tbtn primary" id="peSaveMenu" title="More save options" aria-label="More save options" disabled>
-                <svg width="9" height="9" viewBox="0 0 10 10" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3.8 L5 6.6 L8 3.8"/></svg>
-            </button>
-        </span>
-    </div>
-
-    <div class="pe-stage" id="peStage">
-        <div class="pe-empty" id="peEmpty">
-            No PDF open.<br>Use <strong>Open</strong> to choose a document, or drag one in from the File Manager.
-        </div>
-    </div>
-
-    <div class="pe-props" id="peProps">
-        <label>Font size
-            <input type="range" id="peFontSize" min="8" max="120" value="24" style="width:120px">
-            <span id="peFontVal" style="color:var(--text);font-weight:600;min-width:34px">24px</span>
-        </label>
-        <label>Colour <input type="color" id="peColor" value="#d0021b"></label>
-    </div>
-
-    <div class="pe-toast" id="ptToast"></div>
-
-    <input type="file" id="peUploadInput" accept="image/*" style="display:none">
-    <input type="file" id="peOpenDeviceInput" accept="application/pdf,.pdf" style="display:none">
-    <div class="pe-stamp-menu" id="peStampMenu"></div>
-</div>
-
-<script src="js/common.js"></script>
-<script src="js/chops.js"></script>
-<script src="js/convert.js"></script>
-<script src="js/editor.js"></script>
-<script>
-/* ── ArozOS system theme binding ── */
-function applyAozTheme(theme) {
-    document.documentElement.setAttribute('data-theme', theme === 'dark' ? 'dark' : 'light');
-}
-
-ao_module_onThemeChanged(applyAozTheme);
-
-$.get(ao_root + 'system/file_system/preference?key=file_explorer/theme', function (data) {
-    applyAozTheme(data === 'darkTheme' ? 'dark' : 'light');
-});
-</script>
-</body>
-</html>

+ 0 - 23
src/web/PDF Tool/init.agi

@@ -1,23 +0,0 @@
-/*
-    PDF Tool
-    Edit PDF documents: insert text, images and company chops,
-    export pages as images and build PDFs from images.
-*/
-
-var moduleLaunchInfo = {
-    Name: "PDF Tool",
-    Desc: "Edit PDFs with text, images and company chops",
-    Group: "Office",
-    IconPath: "PDF Tool/img/module_icon.svg",
-    Version: "1.0",
-    StartDir: "PDF Tool/index.html",
-    SupportFW: true,
-    LaunchFWDir: "PDF Tool/index.html",
-    InitFWSize: [1100, 720],
-    SupportEmb: true,
-    LaunchEmb: "PDF Tool/index.html",
-    InitEmbSize: [1100, 720],
-    SupportedExt: [".pdf"]
-}
-
-registerModule(JSON.stringify(moduleLaunchInfo));

+ 0 - 189
src/web/PDF Tool/js/chops.js

@@ -1,189 +0,0 @@
-/*
-    PDF Tool — company chop / stamp library
-
-    Chop PNGs live in the user's hidden app-data folder; only small metadata
-    (id / name / path) goes into preference storage, which is capped at 1 MB and
-    travels over a query string.
-*/
-
-(function (T) {
-    'use strict';
-
-    var DIR = 'user:/.appdata/PDF Tool/Chops/';
-    var MOD = 'PDF Tool', KEY = 'chops';
-    var LEGACY_MOD = 'Productivity'; // pre-rename storage key, migrated on first load
-
-    /*
-        The in-memory cache is the source of truth once loaded.
-        ao_module_storage.setStorage() fires an async write and returns immediately
-        without confirming completion, so reading the value straight back after a
-        save() can race the write and return stale data.
-    */
-    var cache = null;
-    var pending = [];
-    var fetching = false;
-
-    function parse(raw) {
-        if (!raw) { return []; }
-        try { return JSON.parse(raw) || []; } catch (e) { return []; }
-    }
-
-    function flush() {
-        var queued = pending;
-        pending = [];
-        queued.forEach(function (fn) { fn(cache.slice()); });
-    }
-
-    function load(cb) {
-        if (cache !== null) { cb(cache.slice()); return; }
-        pending.push(cb);
-        if (fetching) { return; }
-        fetching = true;
-
-        ao_module_storage.loadStorage(MOD, KEY, function (raw) {
-            var arr = parse(raw);
-            if (arr.length) {
-                cache = arr;
-                fetching = false;
-                flush();
-                return;
-            }
-            // Nothing under the new key — carry any chops saved before the rename forward.
-            ao_module_storage.loadStorage(LEGACY_MOD, KEY, function (legacyRaw) {
-                var legacy = parse(legacyRaw);
-                cache = legacy;
-                fetching = false;
-                if (legacy.length) {
-                    ao_module_storage.setStorage(MOD, KEY, JSON.stringify(legacy));
-                }
-                flush();
-            });
-        });
-    }
-
-    function save(arr, cb) {
-        cache = arr.slice();
-        ao_module_storage.setStorage(MOD, KEY, JSON.stringify(cache));
-        if (cb) { cb(cache.slice()); }
-    }
-
-    function add(srcPath, name, onDone, onErr) {
-        fetch(T.mediaUrl(srcPath)).then(function (r) {
-            if (!r.ok) { throw new Error('Cannot read source image'); }
-            return r.blob();
-        }).then(function (blob) {
-            var fname = 'chop_' + Date.now() + '.png';
-            ao_module_uploadFile(new File([blob], fname, { type: 'image/png' }), DIR, function () {
-                load(function (arr) {
-                    arr.push({ id: 'c' + Date.now(), name: name || 'Chop', path: DIR + fname });
-                    save(arr, function () { if (onDone) { onDone(arr); } });
-                });
-            }, undefined, function (status) {
-                if (onErr) { onErr('Upload failed (' + status + ')'); }
-            });
-        }).catch(function (e) {
-            if (onErr) { onErr(e.message || String(e)); }
-        });
-    }
-
-    function remove(id, onDone) {
-        load(function (arr) {
-            save(arr.filter(function (c) { return c.id !== id; }), onDone);
-        });
-    }
-
-    function rename(id, name, onDone) {
-        load(function (arr) {
-            arr.forEach(function (c) { if (c.id === id) { c.name = name; } });
-            save(arr, onDone);
-        });
-    }
-
-    T.Chops = { DIR: DIR, load: load, save: save, add: add, remove: remove, rename: rename };
-
-    /* ── Manager dialog ─────────────────────────────────────────────── */
-
-    T.openChopManager = function (onChanged) {
-        var dlg = T.modal({
-            title: 'Chop Library',
-            bodyHtml:
-                '<p class="pt-hint">Load your company stamp as a transparent <strong>PNG</strong>. ' +
-                'Saved chops can be placed on any page from the <strong>Stamp</strong> button.</p>' +
-                '<button class="pt-btn primary" id="chopAdd">Add Chop (PNG)</button>' +
-                '<div id="chopMsg"></div>' +
-                '<div id="chopList" style="margin-top:14px"></div>',
-            actions: [{ label: 'Done', primary: false, onClick: function (c) { c.close(); } }]
-        });
-
-        var listEl = dlg.body.querySelector('#chopList');
-        var msgEl = dlg.body.querySelector('#chopMsg');
-
-        function render() {
-            T.Chops.load(function (chops) {
-                if (!chops.length) {
-                    listEl.innerHTML = '<div class="pt-empty-box">No chops yet. Add a transparent PNG of your company stamp to get started.</div>';
-                    return;
-                }
-                var html = '<div class="chop-grid">';
-                chops.forEach(function (c) {
-                    html += '<div class="chop-card">' +
-                        '<div class="chop-thumb"><img src="' + T.mediaUrl(c.path) + '" alt=""></div>' +
-                        '<div class="chop-name">' + T.escHtml(c.name) + '</div>' +
-                        '<div class="chop-card-btns">' +
-                            '<button class="pt-btn tiny" data-rename="' + c.id + '">Rename</button>' +
-                            '<button class="pt-iconbtn danger" data-remove="' + c.id + '" title="Remove">' + T.svg.x + '</button>' +
-                        '</div>' +
-                    '</div>';
-                });
-                listEl.innerHTML = html + '</div>';
-
-                Array.prototype.forEach.call(listEl.querySelectorAll('[data-remove]'), function (btn) {
-                    btn.addEventListener('click', function () {
-                        T.Chops.remove(this.getAttribute('data-remove'), function () {
-                            render();
-                            if (onChanged) { onChanged(); }
-                        });
-                    });
-                });
-                Array.prototype.forEach.call(listEl.querySelectorAll('[data-rename]'), function (btn) {
-                    btn.addEventListener('click', function () {
-                        var id = this.getAttribute('data-rename');
-                        var card = this.closest('.chop-card');
-                        var current = card ? card.querySelector('.chop-name').textContent : '';
-                        var name = prompt('Chop name', current);
-                        if (name != null && name.trim() !== '') {
-                            T.Chops.rename(id, name.trim(), function () {
-                                render();
-                                if (onChanged) { onChanged(); }
-                            });
-                        }
-                    });
-                });
-            });
-        }
-
-        dlg.body.querySelector('#chopAdd').addEventListener('click', function () {
-            ao_module_openFileSelector('_ptChopAddCb', 'user:/', 'file', false, { filter: ['png'] });
-        });
-
-        window._ptChopAddCb = function (files) {
-            if (!files || !files.length) { return; }
-            var f = files[0];
-            if (!/\.png$/i.test(f.filename)) {
-                msgEl.innerHTML = '<div class="result-box result-err">Please choose a <strong>PNG</strong> image (transparent background recommended).</div>';
-                return;
-            }
-            msgEl.innerHTML = '<div class="pt-hint" style="margin-top:8px">Importing chop…</div>';
-            T.Chops.add(f.filepath, f.filename.replace(/\.png$/i, ''), function () {
-                msgEl.innerHTML = '';
-                render();
-                if (onChanged) { onChanged(); }
-            }, function (err) {
-                msgEl.innerHTML = '<div class="result-box result-err"><strong>Error:</strong> ' + T.escHtml(String(err)) + '</div>';
-            });
-        };
-
-        render();
-    };
-
-})(window.PDFTool);

+ 0 - 294
src/web/PDF Tool/js/common.js

@@ -1,294 +0,0 @@
-/*
-    PDF Tool — shared helpers
-
-    Virtual-path utilities, byte/canvas helpers, lazy loaders for the two PDF
-    libraries, and the toast + modal primitives used by the editor and dialogs.
-*/
-
-window.PDFTool = window.PDFTool || {};
-
-(function (T) {
-    'use strict';
-
-    /* ── Virtual path helpers ───────────────────────────────────────── */
-
-    T.dirOf = function (vpath) {
-        var p = vpath.split('/');
-        p.pop();
-        return p.join('/');
-    };
-
-    T.basenameNoExt = function (vpath) {
-        var n = vpath.split('/').pop();
-        var d = n.lastIndexOf('.');
-        return d > 0 ? n.slice(0, d) : n;
-    };
-
-    T.mediaUrl = function (vpath) {
-        return '/media?file=' + encodeURIComponent(vpath);
-    };
-
-    T.escHtml = function (s) {
-        return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
-    };
-
-    /* ── Transfer helpers ───────────────────────────────────────────── */
-
-    T.uploadBlob = function (blob, filename, targetDir) {
-        return new Promise(function (resolve, reject) {
-            ao_module_uploadFile(new File([blob], filename, { type: blob.type }),
-                targetDir, resolve, undefined, reject);
-        });
-    };
-
-    T.fetchBytes = function (url) {
-        return fetch(url).then(function (r) {
-            if (!r.ok) { throw new Error('HTTP ' + r.status); }
-            return r.arrayBuffer();
-        }).then(function (buf) { return new Uint8Array(buf); });
-    };
-
-    T.canvasToBytes = function (c, mime, quality) {
-        return new Promise(function (resolve, reject) {
-            c.toBlob(function (blob) {
-                if (!blob) { reject(new Error('Canvas export failed')); return; }
-                var fr = new FileReader();
-                fr.onload = function (e) { resolve(new Uint8Array(e.target.result)); };
-                fr.onerror = reject;
-                fr.readAsArrayBuffer(blob);
-            }, mime || 'image/png', quality);
-        });
-    };
-
-    T.loadImage = function (src) {
-        return new Promise(function (resolve, reject) {
-            var img = new Image();
-            img.onload = function () { resolve(img); };
-            img.onerror = function () { reject(new Error('Could not load image')); };
-            img.src = src;
-        });
-    };
-
-    /* ── Library loaders (both are lazy; pdf.js is shared with PDF Viewer) ── */
-
-    var pdfJsReady = false;
-
-    T.loadPdfJs = function () {
-        return new Promise(function (resolve, reject) {
-            if (pdfJsReady || typeof pdfjsLib !== 'undefined') {
-                if (!pdfJsReady) {
-                    pdfjsLib.GlobalWorkerOptions.workerSrc = '../PDF Viewer/js/pdf.worker.js';
-                    pdfJsReady = true;
-                }
-                resolve();
-                return;
-            }
-            var s = document.createElement('script');
-            s.src = '../PDF Viewer/js/pdf.js';
-            s.onload = function () {
-                pdfjsLib.GlobalWorkerOptions.workerSrc = '../PDF Viewer/js/pdf.worker.js';
-                pdfJsReady = true;
-                resolve();
-            };
-            s.onerror = function () { reject(new Error('Failed to load the PDF renderer')); };
-            document.head.appendChild(s);
-        });
-    };
-
-    /* pdf-lib (vendored, MIT) — writes real PDF content instead of rasterising */
-    T.loadPdfLib = function () {
-        return new Promise(function (resolve, reject) {
-            if (typeof PDFLib !== 'undefined') { resolve(); return; }
-            var s = document.createElement('script');
-            s.src = 'lib/pdf-lib.min.js';
-            s.onload = function () { resolve(); };
-            s.onerror = function () { reject(new Error('Failed to load pdf-lib')); };
-            document.head.appendChild(s);
-        });
-    };
-
-    /*
-        Fetch an image and normalise it to bytes a PDF can hold directly.
-        PNG and JPEG pass through untouched; anything else is drawn to a canvas and
-        re-encoded as PNG so transparency survives.
-
-        Returns {bytes, isPng}. Kept separate from embedding so a caller can embed
-        the same source more than once and get an independent PDF image object each
-        time (see the editor: every placement is its own layer).
-    */
-    T.imageBytesFor = function (src) {
-        return T.fetchBytes(src).then(function (bytes) {
-            if (bytes[0] === 0x89 && bytes[1] === 0x50) { return { bytes: bytes, isPng: true }; }
-            if (bytes[0] === 0xFF && bytes[1] === 0xD8) { return { bytes: bytes, isPng: false }; }
-            return T.loadImage(src).then(function (img) {
-                var c = document.createElement('canvas');
-                c.width = img.naturalWidth;
-                c.height = img.naturalHeight;
-                c.getContext('2d').drawImage(img, 0, 0);
-                return T.canvasToBytes(c, 'image/png').then(function (png) {
-                    return { bytes: png, isPng: true };
-                });
-            });
-        });
-    };
-
-    /* Embed an image into a pdf-lib document as a fresh, independent image object. */
-    T.embedImage = function (pdfDoc, src) {
-        return T.imageBytesFor(src).then(function (r) {
-            return r.isPng ? pdfDoc.embedPng(r.bytes) : pdfDoc.embedJpg(r.bytes);
-        });
-    };
-
-    /* ── Toast ──────────────────────────────────────────────────────── */
-
-    /* A pill at the bottom centre of the stage. Always fades itself out. */
-    T.toast = function (html, isError) {
-        var el = document.getElementById('ptToast');
-        if (!el) { return; }
-        el.innerHTML = '<div class="pe-pill' + (isError ? ' err' : '') + '">' + html + '</div>';
-        el.classList.add('show');
-        clearTimeout(el._t);
-        el._t = setTimeout(function () { el.classList.remove('show'); }, isError ? 6000 : 4000);
-    };
-
-    T.hideToast = function () {
-        var el = document.getElementById('ptToast');
-        if (el) {
-            clearTimeout(el._t);
-            el.classList.remove('show');
-        }
-    };
-
-    /* ── Dropdown menu ──────────────────────────────────────────────── */
-
-    /*
-        PDFTool.menu(anchorEl, [{label, icon, onClick, disabled}, {separator:true}])
-        Positions itself under the anchor inside .pe-root and closes on outside
-        click or Escape.
-    */
-    T.menu = function (anchor, items) {
-        var root = document.getElementById('peRoot');
-        var existing = root.querySelector('.pe-menu');
-        if (existing) { existing.parentNode.removeChild(existing); }
-
-        var menu = document.createElement('div');
-        menu.className = 'pe-menu';
-
-        items.forEach(function (it) {
-            if (it.separator) {
-                var hr = document.createElement('div');
-                hr.className = 'pe-menu-sep';
-                menu.appendChild(hr);
-                return;
-            }
-            var b = document.createElement('button');
-            b.className = 'pe-menu-item';
-            b.disabled = !!it.disabled;
-            b.innerHTML = '<span class="pe-menu-ico">' + (it.icon || '') + '</span><span>' + T.escHtml(it.label) + '</span>';
-            b.addEventListener('click', function () {
-                close();
-                if (it.onClick) { it.onClick(); }
-            });
-            menu.appendChild(b);
-        });
-
-        function close() {
-            if (menu.parentNode) { menu.parentNode.removeChild(menu); }
-            document.removeEventListener('mousedown', onDoc, true);
-            document.removeEventListener('keydown', onKey);
-        }
-        function onDoc(e) {
-            if (!menu.contains(e.target) && !anchor.contains(e.target)) { close(); }
-        }
-        function onKey(e) { if (e.key === 'Escape') { close(); } }
-
-        root.appendChild(menu);
-
-        // Position under the anchor, clamped to the app's right edge
-        var a = anchor.getBoundingClientRect();
-        var r = root.getBoundingClientRect();
-        var left = a.left - r.left;
-        menu.style.top = (a.bottom - r.top + 6) + 'px';
-        menu.style.left = Math.max(6, Math.min(left, r.width - menu.offsetWidth - 6)) + 'px';
-
-        setTimeout(function () {
-            document.addEventListener('mousedown', onDoc, true);
-            document.addEventListener('keydown', onKey);
-        }, 0);
-
-        return { close: close };
-    };
-
-    /* ── Modal ──────────────────────────────────────────────────────── */
-
-    /*
-        PDFTool.modal({
-            title:      "Dialog title",
-            bodyHtml:   "<p>…</p>",
-            actions:    [{label:"Save", primary:true, onClick:function(ctx){…}}],
-            dismissible:false,          // disables backdrop click + Escape
-            onOpen:     function(ctx){} // ctx = {body, footer, close}
-        })
-    */
-    T.modal = function (opts) {
-        var back = document.createElement('div');
-        back.className = 'pt-modal-back';
-        back.innerHTML =
-            '<div class="pt-modal" role="dialog" aria-modal="true">' +
-                '<div class="pt-modal-hd">' +
-                    '<span>' + T.escHtml(opts.title || '') + '</span>' +
-                    '<button class="pt-modal-x" title="Close" aria-label="Close">' +
-                        '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round">' +
-                        '<line x1="1.5" y1="1.5" x2="10.5" y2="10.5"/><line x1="10.5" y1="1.5" x2="1.5" y2="10.5"/></svg>' +
-                    '</button>' +
-                '</div>' +
-                '<div class="pt-modal-bd"></div>' +
-                '<div class="pt-modal-ft"></div>' +
-            '</div>';
-
-        var body = back.querySelector('.pt-modal-bd');
-        var foot = back.querySelector('.pt-modal-ft');
-        if (opts.bodyHtml) { body.innerHTML = opts.bodyHtml; }
-
-        function close() {
-            if (back.parentNode) { back.parentNode.removeChild(back); }
-            document.removeEventListener('keydown', onKey);
-        }
-
-        function onKey(e) {
-            if (e.key === 'Escape' && opts.dismissible !== false) { close(); }
-        }
-
-        var ctx = { body: body, footer: foot, close: close };
-
-        (opts.actions || []).forEach(function (a) {
-            var b = document.createElement('button');
-            b.className = 'pt-btn' + (a.primary ? ' primary' : '');
-            b.textContent = a.label;
-            b.addEventListener('click', function () {
-                if (a.onClick) { a.onClick({ body: body, footer: foot, close: close, button: b }); }
-            });
-            foot.appendChild(b);
-            if (a.id) { b.id = a.id; }
-        });
-
-        back.querySelector('.pt-modal-x').addEventListener('click', close);
-        back.addEventListener('mousedown', function (e) {
-            if (e.target === back && opts.dismissible !== false) { close(); }
-        });
-        document.addEventListener('keydown', onKey);
-
-        document.body.appendChild(back);
-        if (opts.onOpen) { opts.onOpen(ctx); }
-        return ctx;
-    };
-
-    /* ── Small inline icons ─────────────────────────────────────────── */
-
-    T.svg = {
-        up: '<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2.5 8.5 L6.5 4 L10.5 8.5"/></svg>',
-        down: '<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2.5 4.5 L6.5 9 L10.5 4.5"/></svg>',
-        x: '<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="2" y1="2" x2="11" y2="11"/><line x1="11" y1="2" x2="2" y2="11"/></svg>'
-    };
-
-})(window.PDFTool);

+ 0 - 359
src/web/PDF Tool/js/convert.js

@@ -1,359 +0,0 @@
-/*
-    PDF Tool — conversion dialogs
-
-    "Export Images"  : renders the open document's pages to JPEG/PNG, including
-                       any overlays currently placed (what you see is what you get).
-    "From Images"    : builds a brand new PDF out of a list of images via pdf-lib,
-                       either onto page-sized "base plates" or pages matching each
-                       image. The result can be opened straight in the editor
-                       without ever touching the server.
-*/
-
-(function (T) {
-    'use strict';
-
-    var FONT = "'Helvetica Neue', Arial, sans-serif";
-
-    /* Page sizes in PDF points (72 per inch) */
-    var PAGE_PRESETS = {
-        auto: null,
-        a4p: [595.28, 841.89],
-        a4l: [841.89, 595.28],
-        a3p: [841.89, 1190.55],
-        a3l: [1190.55, 841.89],
-        letterp: [612, 792],
-        letterl: [792, 612],
-        legalp: [612, 1008]
-    };
-
-    /* Draw the editor's overlays onto an export canvas at its own resolution. */
-    function drawOverlays(cx, overlays, W, H, imgMap) {
-        (overlays || []).forEach(function (o) {
-            if (o.type === 'text') {
-                var fontPx = o.fontFrac * H;
-                cx.fillStyle = o.color || '#000';
-                cx.textBaseline = 'top';
-                cx.font = fontPx + 'px ' + FONT;
-                String(o.t).split('\n').forEach(function (ln, i) {
-                    cx.fillText(ln, o.fx * W, o.fy * H + i * fontPx * 1.25);
-                });
-            } else if (o.type === 'image' && imgMap[o.src]) {
-                cx.drawImage(imgMap[o.src], o.fx * W, o.fy * H, o.fwFrac * W, o.fhFrac * H);
-            }
-        });
-    }
-
-    function preloadOverlayImages(overlaysByPage) {
-        var srcs = {};
-        Object.keys(overlaysByPage || {}).forEach(function (k) {
-            (overlaysByPage[k] || []).forEach(function (o) {
-                if (o.type === 'image') { srcs[o.src] = 1; }
-            });
-        });
-        var map = {};
-        return Promise.all(Object.keys(srcs).map(function (src) {
-            return T.loadImage(src).then(function (img) { map[src] = img; },
-                function () { /* skip an image that will not load */ });
-        })).then(function () { return map; });
-    }
-
-    /* ── Export pages as images ─────────────────────────────────────── */
-
-    T.openExportImages = function (doc) {
-        if (!doc || !doc.pdf) { return; }
-        if (!doc.savePath) {
-            T.toast('Save this document first so the images have somewhere to go.', true);
-            return;
-        }
-
-        var dlg = T.modal({
-            title: 'Export Pages as Images',
-            bodyHtml:
-                '<div class="pt-field">' +
-                    '<span class="pt-label">Format</span>' +
-                    '<div class="pt-radios">' +
-                        '<label><input type="radio" name="exFmt" value="jpg" checked> JPEG</label>' +
-                        '<label><input type="radio" name="exFmt" value="png"> PNG</label>' +
-                    '</div>' +
-                '</div>' +
-                '<div class="pt-field" id="exQField">' +
-                    '<span class="pt-label">JPEG quality: <span id="exQVal">90</span>%</span>' +
-                    '<input type="range" id="exQ" min="50" max="100" value="90" style="width:100%">' +
-                '</div>' +
-                '<div class="pt-field">' +
-                    '<span class="pt-label">Resolution</span>' +
-                    '<select class="pt-select" id="exScale">' +
-                        '<option value="1">Standard (1x)</option>' +
-                        '<option value="2" selected>High (2x)</option>' +
-                        '<option value="3">Very high (3x)</option>' +
-                    '</select>' +
-                '</div>' +
-                '<p class="pt-hint">Saved next to the document. Text, images and chops you have placed are included.</p>' +
-                '<div id="exProg"></div>',
-            actions: [
-                { label: 'Cancel', onClick: function (c) { c.close(); } },
-                { label: 'Export', primary: true, onClick: run }
-            ]
-        });
-
-        var qField = dlg.body.querySelector('#exQField');
-        var qRange = dlg.body.querySelector('#exQ');
-        qRange.addEventListener('input', function () {
-            dlg.body.querySelector('#exQVal').textContent = this.value;
-        });
-        Array.prototype.forEach.call(dlg.body.querySelectorAll('input[name=exFmt]'), function (r) {
-            r.addEventListener('change', function () {
-                qField.style.display = this.value === 'jpg' ? '' : 'none';
-            });
-        });
-
-        function run(ctx) {
-            var fmt = dlg.body.querySelector('input[name=exFmt]:checked').value;
-            var quality = parseInt(qRange.value, 10) / 100;
-            var scale = parseFloat(dlg.body.querySelector('#exScale').value);
-            var mime = fmt === 'png' ? 'image/png' : 'image/jpeg';
-            var ext = fmt === 'png' ? '.png' : '.jpg';
-            var outDir = T.dirOf(doc.savePath);
-            var base = T.basenameNoExt(doc.savePath);
-            var prog = dlg.body.querySelector('#exProg');
-
-            ctx.button.disabled = true;
-            prog.innerHTML = '<div class="pt-hint">Preparing…</div>';
-
-            preloadOverlayImages(doc.overlays).then(function (imgMap) {
-                var n = doc.pdf.numPages;
-
-                function fail(err) {
-                    prog.innerHTML = '<div class="result-box result-err"><strong>Error:</strong> ' +
-                        T.escHtml(String(err && err.message ? err.message : err)) + '</div>';
-                    ctx.button.disabled = false;
-                }
-
-                function next(i) {
-                    if (i > n) {
-                        prog.innerHTML = '<div class="result-box result-ok"><strong>' + n +
-                            ' image' + (n !== 1 ? 's' : '') + '</strong> saved to ' + T.escHtml(outDir) + '</div>';
-                        ctx.button.disabled = false;
-                        return;
-                    }
-                    prog.innerHTML = '<div class="pt-hint">Rendering page ' + i + ' of ' + n + '…</div>';
-
-                    doc.pdf.getPage(i).then(function (page) {
-                        var vp = page.getViewport({ scale: scale });
-                        var c = document.createElement('canvas');
-                        c.width = vp.width;
-                        c.height = vp.height;
-                        var cx = c.getContext('2d');
-                        if (fmt !== 'png') {
-                            cx.fillStyle = '#FFF';
-                            cx.fillRect(0, 0, c.width, c.height);
-                        }
-                        page.render({ canvasContext: cx, viewport: vp }).promise.then(function () {
-                            drawOverlays(cx, doc.overlays[i], c.width, c.height, imgMap);
-                            c.toBlob(function (blob) {
-                                T.uploadBlob(blob, base + '_page' + i + ext, outDir)
-                                    .then(function () { next(i + 1); }, fail);
-                            }, mime, quality);
-                        }, fail);
-                    }, fail);
-                }
-
-                next(1);
-            });
-        }
-    };
-
-    /* ── Build a PDF from images ────────────────────────────────────── */
-
-    T.openImagesToPdf = function () {
-        var images = [];
-        var overrideDir = null;
-
-        var dlg = T.modal({
-            title: 'Create PDF from Images',
-            bodyHtml:
-                '<div class="pt-field">' +
-                    '<span class="pt-label">Images</span>' +
-                    '<div id="i2pList"></div>' +
-                    '<button class="pt-btn" id="i2pAdd" style="margin-top:8px">Add Images…</button>' +
-                '</div>' +
-                '<div class="pt-field">' +
-                    '<span class="pt-label">Page size</span>' +
-                    '<select class="pt-select" id="i2pSize">' +
-                        '<option value="auto" selected>Match each image</option>' +
-                        '<option value="a4p">A4 portrait</option>' +
-                        '<option value="a4l">A4 landscape</option>' +
-                        '<option value="a3p">A3 portrait</option>' +
-                        '<option value="a3l">A3 landscape</option>' +
-                        '<option value="letterp">Letter portrait</option>' +
-                        '<option value="letterl">Letter landscape</option>' +
-                        '<option value="legalp">Legal portrait</option>' +
-                    '</select>' +
-                    '<p class="pt-hint" style="margin:6px 0 0">Images are scaled to fit and centred on the page. ' +
-                    'Nothing is cropped and the aspect ratio is kept.</p>' +
-                '</div>' +
-                '<div class="pt-field">' +
-                    '<span class="pt-label">Output filename</span>' +
-                    '<input type="text" class="pt-input" id="i2pName" placeholder="output.pdf">' +
-                '</div>' +
-                '<div class="pt-field">' +
-                    '<span class="pt-label">Save to folder</span>' +
-                    '<div class="pt-row">' +
-                        '<button class="pt-btn" id="i2pDir">Choose…</button>' +
-                        '<span class="pt-path" id="i2pDirLbl">Same folder as the first image</span>' +
-                    '</div>' +
-                '</div>' +
-                '<div id="i2pProg"></div>',
-            actions: [
-                { label: 'Cancel', onClick: function (c) { c.close(); } },
-                { label: 'Open in Editor', onClick: openInEditor },
-                { label: 'Save to Server', primary: true, onClick: saveToServer }
-            ]
-        });
-
-        var listEl = dlg.body.querySelector('#i2pList');
-        var progEl = dlg.body.querySelector('#i2pProg');
-
-        function renderList() {
-            if (!images.length) {
-                listEl.innerHTML = '<div class="pt-empty-box">No images added yet.</div>';
-                return;
-            }
-            var html = '<div class="pt-imglist">';
-            images.forEach(function (img, idx) {
-                html += '<div class="pt-imgrow">' +
-                    '<img class="pt-thumb" src="' + T.mediaUrl(img.filepath) + '" alt="">' +
-                    '<span class="pt-imgname">' + T.escHtml(img.filename) + '</span>' +
-                    '<span class="pt-imgbtns">' +
-                        (idx > 0 ? '<button class="pt-iconbtn" data-mv="-1" data-i="' + idx + '" title="Move up">' + T.svg.up + '</button>' : '') +
-                        (idx < images.length - 1 ? '<button class="pt-iconbtn" data-mv="1" data-i="' + idx + '" title="Move down">' + T.svg.down + '</button>' : '') +
-                        '<button class="pt-iconbtn danger" data-rm="' + idx + '" title="Remove">' + T.svg.x + '</button>' +
-                    '</span>' +
-                '</div>';
-            });
-            listEl.innerHTML = html + '</div>';
-
-            Array.prototype.forEach.call(listEl.querySelectorAll('[data-mv]'), function (b) {
-                b.addEventListener('click', function () {
-                    var i = parseInt(this.getAttribute('data-i'), 10);
-                    var j = i + parseInt(this.getAttribute('data-mv'), 10);
-                    if (j < 0 || j >= images.length) { return; }
-                    var tmp = images[i]; images[i] = images[j]; images[j] = tmp;
-                    renderList();
-                });
-            });
-            Array.prototype.forEach.call(listEl.querySelectorAll('[data-rm]'), function (b) {
-                b.addEventListener('click', function () {
-                    images.splice(parseInt(this.getAttribute('data-rm'), 10), 1);
-                    renderList();
-                });
-            });
-        }
-
-        dlg.body.querySelector('#i2pAdd').addEventListener('click', function () {
-            ao_module_openFileSelector('_ptI2pAddCb', 'user:/', 'file', true,
-                { filter: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'] });
-        });
-        dlg.body.querySelector('#i2pDir').addEventListener('click', function () {
-            ao_module_openFileSelector('_ptI2pDirCb', 'user:/', 'folder', false);
-        });
-
-        window._ptI2pAddCb = function (files) {
-            if (!files || !files.length) { return; }
-            files.forEach(function (f) {
-                if (!images.some(function (x) { return x.filepath === f.filepath; })) {
-                    images.push({ filepath: f.filepath, filename: f.filename });
-                }
-            });
-            renderList();
-        };
-        window._ptI2pDirCb = function (files) {
-            if (!files || !files.length) { return; }
-            overrideDir = files[0].filepath;
-            dlg.body.querySelector('#i2pDirLbl').textContent = overrideDir;
-        };
-
-        function outputName() {
-            var name = dlg.body.querySelector('#i2pName').value.trim() || 'output';
-            return /\.pdf$/i.test(name) ? name : name + '.pdf';
-        }
-
-        /* Build the document in memory and hand back its bytes. */
-        function build(ctx) {
-            if (!images.length) {
-                progEl.innerHTML = '<div class="result-box result-err">Add at least one image first.</div>';
-                return Promise.reject(null);
-            }
-            var preset = PAGE_PRESETS[dlg.body.querySelector('#i2pSize').value] || null;
-
-            ctx.button.disabled = true;
-            progEl.innerHTML = '<div class="pt-hint">Loading pdf-lib…</div>';
-
-            return T.loadPdfLib().then(function () {
-                return PDFLib.PDFDocument.create();
-            }).then(function (pdfDoc) {
-                return images.reduce(function (chain, im, i) {
-                    return chain.then(function () {
-                        progEl.innerHTML = '<div class="pt-hint">Adding image ' + (i + 1) + ' of ' + images.length + '…</div>';
-                        return T.embedImage(pdfDoc, T.mediaUrl(im.filepath)).then(function (emb) {
-                            if (!preset) {
-                                // One page per image, exactly the image's own size
-                                var p = pdfDoc.addPage([emb.width, emb.height]);
-                                p.drawImage(emb, { x: 0, y: 0, width: emb.width, height: emb.height });
-                                return;
-                            }
-                            // Fixed base plate: scale to fit inside, keep aspect, centre it
-                            var pw = preset[0], ph = preset[1];
-                            var s = Math.min(pw / emb.width, ph / emb.height);
-                            var w = emb.width * s, h = emb.height * s;
-                            var page = pdfDoc.addPage([pw, ph]);
-                            page.drawImage(emb, { x: (pw - w) / 2, y: (ph - h) / 2, width: w, height: h });
-                        });
-                    });
-                }, Promise.resolve()).then(function () {
-                    progEl.innerHTML = '<div class="pt-hint">Writing PDF…</div>';
-                    return pdfDoc.save();
-                });
-            }).catch(function (err) {
-                if (err) {
-                    progEl.innerHTML = '<div class="result-box result-err"><strong>Error:</strong> ' +
-                        T.escHtml(String(err.message || err)) + '</div>';
-                }
-                ctx.button.disabled = false;
-                throw err;
-            });
-        }
-
-        /* Straight into the editor — never round-trips through the server */
-        function openInEditor(ctx) {
-            build(ctx).then(function (bytes) {
-                ctx.button.disabled = false;
-                ctx.close();
-                T.openBytes(bytes, outputName(), null);
-            }).catch(function () { /* message already shown */ });
-        }
-
-        function saveToServer(ctx) {
-            var name = outputName();
-            build(ctx).then(function (bytes) {
-                var outDir = overrideDir || T.dirOf(images[0].filepath);
-                progEl.innerHTML = '<div class="pt-hint">Uploading…</div>';
-                return T.uploadBlob(new Blob([bytes], { type: 'application/pdf' }), name, outDir)
-                    .then(function () {
-                        progEl.innerHTML = '<div class="result-box result-ok"><strong>' + T.escHtml(name) +
-                            '</strong> created in ' + T.escHtml(outDir) + '</div>';
-                        ctx.button.disabled = false;
-                    });
-            }).catch(function (err) {
-                if (err) {
-                    progEl.innerHTML = '<div class="result-box result-err"><strong>Error:</strong> ' +
-                        T.escHtml(String(err.message || err)) + '</div>';
-                }
-                ctx.button.disabled = false;
-            });
-        }
-
-        renderList();
-    };
-
-})(window.PDFTool);

+ 0 - 775
src/web/PDF Tool/js/editor.js

@@ -1,775 +0,0 @@
-/*
-    PDF Tool — editor
-
-    Renders the open document with pdf.js and lets the user place text, images
-    and chops on top. Saving re-opens the ORIGINAL bytes with pdf-lib and draws
-    the overlays as real PDF content, so pages keep their vector text and pages
-    without overlays are left untouched.
-
-    The pristine source bytes are held in memory for the life of the document, so
-    saving repeatedly (or overwriting the source file) never re-applies overlays
-    on top of an already-stamped copy.
-*/
-
-(function (T) {
-    'use strict';
-
-    var FONT = "'Helvetica Neue', Arial, sans-serif";
-    var TEXT_BASELINE_RATIO = 0.8; // top of a line to its baseline, as a fraction of font size
-
-    /*
-        doc.srcBytes — pristine original, never mutated
-        doc.savePath — where it lives on the server, or null for a document that
-                       was built in memory (From Images) and not saved yet
-    */
-    var doc = {
-        pdf: null, srcBytes: null, savePath: null, filename: '',
-        page: 1, num: 0, overlays: {}
-    };
-    T.doc = doc;
-
-    var zoom = 'fit'; // 'fit' or a numeric scale (1 = 100%)
-    var sel = null;
-    var resizeTimer = null;
-    var canvas, overlayEl, stageEl, propsEl, stampMenu, zoomEl, fileNameEl, rootEl;
-    var editButtons = [];
-
-    function $(id) { return document.getElementById(id); }
-
-    function enableEditing(on) {
-        editButtons.forEach(function (b) { b.disabled = !on; });
-    }
-
-    /* ── Selection ──────────────────────────────────────────────────── */
-
-    function selectOverlay(o, el) {
-        clearSelection();
-        sel = { o: o, el: el };
-        el.classList.add('selected');
-        if (o.type === 'text') {
-            propsEl.classList.add('show');
-            rootEl.classList.add('props-open'); // lifts the toast clear of the bar
-            var px = Math.round(o.fontFrac * canvas.height);
-            $('peFontSize').value = px;
-            $('peFontVal').textContent = px + 'px';
-            $('peColor').value = o.color || '#000000';
-        }
-    }
-
-    function clearSelection() {
-        if (sel) { sel.el.classList.remove('selected'); }
-        sel = null;
-        propsEl.classList.remove('show');
-        rootEl.classList.remove('props-open');
-    }
-
-    /* ── Overlay elements ───────────────────────────────────────────── */
-
-    function makeOverlayEl(o) {
-        var el = document.createElement('div');
-        el.className = 'pe-ov ' + (o.type === 'text' ? 'pe-text' : 'pe-img');
-        el.style.left = (o.fx * canvas.width) + 'px';
-        el.style.top = (o.fy * canvas.height) + 'px';
-
-        if (o.type === 'text') {
-            el.textContent = o.t;
-            el.style.fontSize = (o.fontFrac * canvas.height) + 'px';
-            el.style.color = o.color || '#000';
-            el.addEventListener('dblclick', function () {
-                el.setAttribute('contenteditable', 'true');
-                el.focus();
-            });
-            el.addEventListener('blur', function () {
-                el.removeAttribute('contenteditable');
-                o.t = el.textContent;
-                o.fx = el.offsetLeft / canvas.width;
-                o.fy = el.offsetTop / canvas.height;
-            });
-        } else {
-            el.style.width = (o.fwFrac * canvas.width) + 'px';
-            el.style.height = (o.fhFrac * canvas.height) + 'px';
-            var img = document.createElement('img');
-            img.src = o.src;
-            el.appendChild(img);
-            var handle = document.createElement('div');
-            handle.className = 'pe-handle';
-            el.appendChild(handle);
-            wireResize(handle, el, o);
-        }
-
-        var del = document.createElement('button');
-        del.className = 'pe-del';
-        del.innerHTML = '<svg width="9" height="9" viewBox="0 0 9 9" fill="none" stroke="#fff" stroke-width="1.6" stroke-linecap="round"><line x1="1" y1="1" x2="8" y2="8"/><line x1="8" y1="1" x2="1" y2="8"/></svg>';
-        del.addEventListener('mousedown', function (e) { e.stopPropagation(); });
-        del.addEventListener('click', function (e) {
-            e.stopPropagation();
-            var arr = doc.overlays[doc.page] || [];
-            var i = arr.indexOf(o);
-            if (i !== -1) { arr.splice(i, 1); }
-            clearSelection();
-            el.parentNode.removeChild(el);
-        });
-        el.appendChild(del);
-
-        wireDrag(el, o);
-        el.addEventListener('mousedown', function () { selectOverlay(o, el); });
-        return el;
-    }
-
-    function wireDrag(el, o) {
-        el.addEventListener('mousedown', function (e) {
-            if (el.getAttribute('contenteditable') === 'true') { return; }
-            if (e.target.classList.contains('pe-handle')) { return; }
-            e.preventDefault();
-            var startX = e.clientX, startY = e.clientY;
-            var baseL = el.offsetLeft, baseT = el.offsetTop;
-            function mv(ev) {
-                var nl = Math.max(0, Math.min(canvas.width - 6, baseL + (ev.clientX - startX)));
-                var nt = Math.max(0, Math.min(canvas.height - 6, baseT + (ev.clientY - startY)));
-                el.style.left = nl + 'px';
-                el.style.top = nt + 'px';
-                o.fx = nl / canvas.width;
-                o.fy = nt / canvas.height;
-            }
-            function up() {
-                document.removeEventListener('mousemove', mv);
-                document.removeEventListener('mouseup', up);
-            }
-            document.addEventListener('mousemove', mv);
-            document.addEventListener('mouseup', up);
-        });
-    }
-
-    function wireResize(handle, el, o) {
-        handle.addEventListener('mousedown', function (e) {
-            e.preventDefault();
-            e.stopPropagation();
-            var startX = e.clientX;
-            var startW = el.offsetWidth;
-            var aspect = el.offsetHeight / el.offsetWidth;
-            function mv(ev) {
-                var nw = Math.max(18, Math.min(canvas.width, startW + (ev.clientX - startX)));
-                var nh = nw * aspect;
-                el.style.width = nw + 'px';
-                el.style.height = nh + 'px';
-                o.fwFrac = nw / canvas.width;
-                o.fhFrac = nh / canvas.height;
-            }
-            function up() {
-                document.removeEventListener('mousemove', mv);
-                document.removeEventListener('mouseup', up);
-            }
-            document.addEventListener('mousemove', mv);
-            document.addEventListener('mouseup', up);
-        });
-    }
-
-    function addOverlay(o) {
-        if (!doc.overlays[doc.page]) { doc.overlays[doc.page] = []; }
-        doc.overlays[doc.page].push(o);
-        if (overlayEl) {
-            var el = makeOverlayEl(o);
-            overlayEl.appendChild(el);
-            selectOverlay(o, el);
-        }
-    }
-
-    /* ── Rendering (Fit fills the stage; a numeric zoom scrolls) ────── */
-
-    function pageScale(v1) {
-        if (zoom === 'fit') {
-            var availW = Math.max(80, stageEl.clientWidth - 28);
-            var availH = Math.max(80, stageEl.clientHeight - 28);
-            return Math.min(availW / v1.width, availH / v1.height, 4);
-        }
-        return zoom;
-    }
-
-    function renderPage(n) {
-        if (!doc.pdf) { return; }
-        clearSelection();
-        doc.pdf.getPage(n).then(function (page) {
-            var v1 = page.getViewport({ scale: 1 });
-            var vp = page.getViewport({ scale: pageScale(v1) });
-
-            stageEl.classList.toggle('zoomed', zoom !== 'fit');
-            stageEl.innerHTML = '';
-
-            var wrap = document.createElement('div');
-            wrap.className = 'pe-wrap';
-            wrap.style.width = vp.width + 'px';
-            wrap.style.height = vp.height + 'px';
-
-            canvas = document.createElement('canvas');
-            canvas.width = vp.width;
-            canvas.height = vp.height;
-            overlayEl = document.createElement('div');
-            overlayEl.className = 'pe-overlay';
-            wrap.appendChild(canvas);
-            wrap.appendChild(overlayEl);
-            stageEl.appendChild(wrap);
-
-            overlayEl.addEventListener('mousedown', function (e) {
-                if (e.target === overlayEl) { clearSelection(); }
-            });
-
-            page.render({ canvasContext: canvas.getContext('2d'), viewport: vp }).promise.then(function () {
-                (doc.overlays[n] || []).forEach(function (o) { overlayEl.appendChild(makeOverlayEl(o)); });
-            });
-
-            $('pePageLbl').textContent = n + ' / ' + doc.num;
-            $('pePrev').disabled = (n <= 1);
-            $('peNext').disabled = (n >= doc.num);
-        });
-    }
-
-    /* ── Opening ────────────────────────────────────────────────────── */
-
-    /*
-        Open a document from raw bytes. savePath is the file it came from, or null
-        when it only exists in memory (built by "From Images" and not saved yet).
-    */
-    function openBytes(bytes, filename, savePath) {
-        doc.srcBytes = bytes;
-        doc.savePath = savePath || null;
-        doc.filename = filename;
-        doc.overlays = {};
-        doc.page = 1;
-        zoom = 'fit';
-        zoomEl.value = 'fit';
-
-        fileNameEl.textContent = filename + (doc.savePath ? '' : ' (unsaved)');
-        fileNameEl.title = doc.savePath || filename + ' — not saved yet';
-        T.hideToast();
-        stageEl.classList.remove('zoomed');
-        stageEl.innerHTML = '<div class="pe-empty">Opening…</div>';
-        ao_module_setWindowTitle(filename + ' - PDF Tool');
-
-        return T.loadPdfJs().then(function () {
-            // pdf.js may transfer the buffer to its worker, so hand it a copy
-            return pdfjsLib.getDocument({ data: bytes.slice(0) }).promise;
-        }).then(function (pdf) {
-            doc.pdf = pdf;
-            doc.num = pdf.numPages;
-            doc.page = 1;
-            enableEditing(true);
-            renderPage(1);
-        }).catch(function (err) {
-            stageEl.innerHTML = '<div class="pe-empty">Could not open this PDF:<br>' +
-                T.escHtml(String(err && err.message ? err.message : err)) + '</div>';
-        });
-    }
-
-    T.openBytes = openBytes;
-
-    function openPdf(filepath, filename) {
-        stageEl.innerHTML = '<div class="pe-empty">Loading…</div>';
-        return T.fetchBytes(T.mediaUrl(filepath)).then(function (bytes) {
-            return openBytes(bytes, filename || filepath.split('/').pop(), filepath);
-        }).catch(function (err) {
-            stageEl.innerHTML = '<div class="pe-empty">Could not read this file:<br>' +
-                T.escHtml(String(err && err.message ? err.message : err)) + '</div>';
-        });
-    }
-
-    function placeImageFromSrc(src) {
-        if (!canvas) { return; }
-        T.loadImage(src).then(function (probe) {
-            var dispW = Math.min(150, canvas.width * 0.32);
-            var dispH = dispW * (probe.naturalHeight / probe.naturalWidth);
-            addOverlay({
-                type: 'image', src: src, fx: 0.4, fy: 0.4,
-                fwFrac: dispW / canvas.width, fhFrac: dispH / canvas.height
-            });
-        }).catch(function () {
-            T.toast('Could not load that image.', true);
-        });
-    }
-
-    /* ── Stamp picker ───────────────────────────────────────────────── */
-
-    function openStampMenu(anchor) {
-        T.Chops.load(function (chops) {
-            if (!chops.length) {
-                stampMenu.innerHTML = '<div class="pe-stamp-empty">No chops saved yet.<br>' +
-                    '<button class="pt-btn tiny" id="peStampManage" style="margin-top:8px">Open Chop Library</button></div>';
-            } else {
-                var html = '<div class="pe-stamp-grid">';
-                chops.forEach(function (c) {
-                    html += '<div class="pe-stamp-item" data-src="' + T.mediaUrl(c.path) + '">' +
-                        '<img src="' + T.mediaUrl(c.path) + '" alt=""><span>' + T.escHtml(c.name) + '</span></div>';
-                });
-                html += '</div><button class="pt-btn tiny" id="peStampManage" style="margin-top:9px;width:100%">Manage chops…</button>';
-                stampMenu.innerHTML = html;
-
-                Array.prototype.forEach.call(stampMenu.querySelectorAll('.pe-stamp-item'), function (it) {
-                    it.addEventListener('click', function () {
-                        placeImageFromSrc(this.getAttribute('data-src'));
-                        stampMenu.classList.remove('show');
-                    });
-                });
-            }
-            var manage = stampMenu.querySelector('#peStampManage');
-            if (manage) {
-                manage.addEventListener('click', function () {
-                    stampMenu.classList.remove('show');
-                    T.openChopManager();
-                });
-            }
-            stampMenu.style.left = anchor.offsetLeft + 'px';
-            stampMenu.style.top = (anchor.offsetTop + anchor.offsetHeight + 6) + 'px';
-            stampMenu.classList.add('show');
-        });
-    }
-
-    /* ── Building the edited document ───────────────────────────────── */
-
-    function rasteriseText(o, fontPt) {
-        var lines = String(o.t).split('\n');
-        var probe = document.createElement('canvas').getContext('2d');
-        probe.font = fontPt + 'px ' + FONT;
-        var wPt = 1;
-        lines.forEach(function (ln) { wPt = Math.max(wPt, probe.measureText(ln).width); });
-        var lineH = fontPt * 1.25;
-        var hPt = lines.length * lineH;
-        var k = 3; // supersample for crisp glyphs
-        var c = document.createElement('canvas');
-        c.width = Math.max(1, Math.ceil(wPt * k));
-        c.height = Math.max(1, Math.ceil(hPt * k));
-        var cx = c.getContext('2d');
-        cx.scale(k, k);
-        cx.fillStyle = o.color || '#000';
-        cx.textBaseline = 'top';
-        cx.font = fontPt + 'px ' + FONT;
-        lines.forEach(function (ln, i) { cx.fillText(ln, 0, i * lineH); });
-        return { canvas: c, wPt: wPt, hPt: hPt };
-    }
-
-    function hexToRgb(hex) {
-        hex = (hex || '#000000').replace('#', '');
-        if (hex.length === 3) { hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; }
-        return {
-            r: parseInt(hex.substr(0, 2), 16) / 255,
-            g: parseInt(hex.substr(2, 2), 16) / 255,
-            b: parseInt(hex.substr(4, 2), 16) / 255
-        };
-    }
-
-    /*
-        Apply every overlay to a copy of the original document and return the bytes.
-        Each image placement is embedded as its OWN PDF image object inside its own
-        graphics state, so overlapping images stay independent objects in the output
-        instead of being flattened together.
-    */
-    function buildEditedBytes(status) {
-        var byteCache = {}; // src -> Promise<{bytes,isPng}>, avoids re-decoding one source
-
-        function embedFresh(pdfDoc, src) {
-            if (!byteCache[src]) { byteCache[src] = T.imageBytesFor(src); }
-            return byteCache[src].then(function (r) {
-                return r.isPng ? pdfDoc.embedPng(r.bytes) : pdfDoc.embedJpg(r.bytes);
-            });
-        }
-
-        return T.loadPdfLib().then(function () {
-            return PDFLib.PDFDocument.load(doc.srcBytes.slice(0), { ignoreEncryption: true });
-        }).then(function (pdfDoc) {
-            var degrees = PDFLib.degrees, rgb = PDFLib.rgb;
-            return pdfDoc.embedFont(PDFLib.StandardFonts.Helvetica).then(function (helv) {
-                var libPages = pdfDoc.getPages();
-                var pageKeys = Object.keys(doc.overlays).filter(function (k) {
-                    return (doc.overlays[k] || []).length;
-                });
-
-                // Walk only the pages that actually carry overlays, in order.
-                return pageKeys.reduce(function (chain, k) {
-                    return chain.then(function () {
-                        var pn = parseInt(k, 10);
-                        var libPage = libPages[pn - 1];
-                        if (!libPage) { return; }
-                        if (status) { status('Writing page ' + pn + '…'); }
-
-                        return doc.pdf.getPage(pn).then(function (jsPage) {
-                            var vp = jsPage.getViewport({ scale: 1 });
-                            var rot = vp.rotation || 0;
-
-                            return (doc.overlays[pn] || []).reduce(function (c2, o) {
-                                return c2.then(function () {
-                                    var dx = o.fx * vp.width, dy = o.fy * vp.height;
-
-                                    if (o.type === 'image') {
-                                        var ew = o.fwFrac * vp.width, eh = o.fhFrac * vp.height;
-                                        var bl = vp.convertToPdfPoint(dx, dy + eh);
-                                        // Fresh embed per placement keeps each one a separate layer
-                                        return embedFresh(pdfDoc, o.src).then(function (img) {
-                                            libPage.pushOperators(PDFLib.pushGraphicsState());
-                                            libPage.drawImage(img, {
-                                                x: bl[0], y: bl[1], width: ew, height: eh, rotate: degrees(rot)
-                                            });
-                                            libPage.pushOperators(PDFLib.popGraphicsState());
-                                        });
-                                    }
-
-                                    var fontPt = o.fontFrac * vp.height;
-                                    var col = hexToRgb(o.color);
-                                    var canEncode = true;
-                                    try { helv.encodeText(o.t); } catch (e) { canEncode = false; }
-
-                                    if (canEncode) {
-                                        libPage.pushOperators(PDFLib.pushGraphicsState());
-                                        String(o.t).split('\n').forEach(function (ln, i) {
-                                            var topY = dy + TEXT_BASELINE_RATIO * fontPt + i * fontPt * 1.25;
-                                            var pt = vp.convertToPdfPoint(dx, topY);
-                                            libPage.drawText(ln, {
-                                                x: pt[0], y: pt[1], size: fontPt, font: helv,
-                                                color: rgb(col.r, col.g, col.b), rotate: degrees(rot)
-                                            });
-                                        });
-                                        libPage.pushOperators(PDFLib.popGraphicsState());
-                                        return;
-                                    }
-
-                                    // Glyphs the standard font cannot encode (e.g. CJK):
-                                    // rasterise just this text box and place it as an image.
-                                    var rt = rasteriseText(o, fontPt);
-                                    var blt = vp.convertToPdfPoint(dx, dy + rt.hPt);
-                                    return T.canvasToBytes(rt.canvas, 'image/png')
-                                        .then(function (png) { return pdfDoc.embedPng(png); })
-                                        .then(function (img) {
-                                            libPage.pushOperators(PDFLib.pushGraphicsState());
-                                            libPage.drawImage(img, {
-                                                x: blt[0], y: blt[1], width: rt.wPt, height: rt.hPt, rotate: degrees(rot)
-                                            });
-                                            libPage.pushOperators(PDFLib.popGraphicsState());
-                                        });
-                                });
-                            }, Promise.resolve());
-                        });
-                    });
-                }, Promise.resolve()).then(function () { return pdfDoc.save(); });
-            });
-        });
-    }
-
-    /* ── Saving ─────────────────────────────────────────────────────── */
-
-    function writeTo(dir, name, onFinished) {
-        var btn = $('peSave');
-        var label = btn.innerHTML;
-        btn.disabled = true;
-
-        function status(t) { btn.textContent = t; }
-        function done() { btn.innerHTML = label; btn.disabled = false; }
-
-        status('Saving…');
-        buildEditedBytes(status).then(function (outBytes) {
-            status('Uploading…');
-            return T.uploadBlob(new Blob([outBytes], { type: 'application/pdf' }), name, dir);
-        }).then(function () {
-            var full = dir.replace(/\/$/, '') + '/' + name;
-            // The in-memory original stays pristine, so overlays remain editable and
-            // are never applied twice — even when we just overwrote the source file.
-            doc.savePath = full;
-            doc.filename = name;
-            fileNameEl.textContent = name;
-            fileNameEl.title = full;
-            ao_module_setWindowTitle(name + ' - PDF Tool');
-            T.toast('<strong>' + T.escHtml(name) + '</strong> saved to ' + T.escHtml(dir) + '.', false);
-            done();
-            if (onFinished) { onFinished(); }
-        }).catch(function (err) {
-            T.toast('<strong>Error:</strong> ' + T.escHtml(String(err && err.message ? err.message : err)), true);
-            done();
-        });
-    }
-
-    /*
-        Build the edited document and hand it to the browser's downloader, so it
-        lands on the user's own device without going through the server at all.
-    */
-    function downloadPdf() {
-        if (!doc.pdf) { return; }
-        clearSelection();
-
-        var btn = $('peSave');
-        var label = btn.innerHTML;
-        btn.disabled = true;
-
-        function status(t) { btn.textContent = t; }
-        function done() { btn.innerHTML = label; btn.disabled = false; }
-
-        status('Preparing…');
-        buildEditedBytes(status).then(function (outBytes) {
-            var name = doc.filename || 'document.pdf';
-            if (!/\.pdf$/i.test(name)) { name += '.pdf'; }
-
-            var url = URL.createObjectURL(new Blob([outBytes], { type: 'application/pdf' }));
-            var a = document.createElement('a');
-            a.href = url;
-            a.download = name;
-            a.style.display = 'none';
-            document.body.appendChild(a);
-            a.click();
-            document.body.removeChild(a);
-            // Let the transfer start before the blob is released
-            setTimeout(function () { URL.revokeObjectURL(url); }, 10000);
-
-            T.toast('<strong>' + T.escHtml(name) + '</strong> downloaded.', false);
-            done();
-        }).catch(function (err) {
-            T.toast('<strong>Error:</strong> ' + T.escHtml(String(err && err.message ? err.message : err)), true);
-            done();
-        });
-    }
-
-    function save() {
-        if (!doc.pdf) { return; }
-        clearSelection();
-
-        var canOverwrite = !!doc.savePath;
-        var actions = [{ label: 'Cancel', onClick: function (c) { c.close(); } }];
-
-        actions.push({
-            label: 'Save As…',
-            primary: !canOverwrite,
-            onClick: function (c) {
-                c.close();
-                var startDir = doc.savePath ? T.dirOf(doc.savePath) : 'user:/Desktop';
-                var defName = canOverwrite
-                    ? T.basenameNoExt(doc.filename) + '_edited.pdf'
-                    : doc.filename;
-                ao_module_openFileSelector('_ptSaveAsCb', startDir, 'new', false, { defaultName: defName });
-            }
-        });
-
-        if (canOverwrite) {
-            actions.push({
-                label: 'Overwrite',
-                primary: true,
-                onClick: function (c) {
-                    c.close();
-                    writeTo(T.dirOf(doc.savePath), doc.savePath.split('/').pop());
-                }
-            });
-        }
-
-        T.modal({
-            title: 'Save PDF',
-            bodyHtml: canOverwrite
-                ? '<p class="pt-hint">Overwrite the original file, or write the result to a new one.</p>' +
-                  '<span class="pt-label">Current file</span>' +
-                  '<div class="pt-pathbox">' + T.escHtml(doc.savePath) + '</div>'
-                : '<p class="pt-hint">This document is read only, use Save As to save a copy.</p>' +
-                  '<div class="pt-empty-box">Not saved yet</div>',
-            actions: actions
-        });
-    }
-
-    window._ptSaveAsCb = function (files) {
-        if (!files || !files.length) { return; }
-        var fp = files[0].filepath;
-        var name = files[0].filename || fp.split('/').pop();
-        if (!/\.pdf$/i.test(name)) {
-            name += '.pdf';
-            fp += '.pdf';
-        }
-        writeTo(T.dirOf(fp), name);
-    };
-
-    /* ── Boot ───────────────────────────────────────────────────────── */
-
-    function boot() {
-        rootEl = $('peRoot');
-        stageEl = $('peStage');
-        propsEl = $('peProps');
-        stampMenu = $('peStampMenu');
-        zoomEl = $('peZoom');
-        fileNameEl = $('peFileName');
-
-        editButtons = ['peAddText', 'peAddImg', 'peUpload', 'peAddStamp', 'peSave', 'peSaveMenu', 'peZoom']
-            .map(function (id) { return $(id); });
-
-        var ICON = {
-            server: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="1.5" y="2" width="11" height="4" rx="1"/><rect x="1.5" y="8" width="11" height="4" rx="1"/><circle cx="4" cy="4" r="0.6" fill="currentColor"/><circle cx="4" cy="10" r="0.6" fill="currentColor"/></svg>',
-            device: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M7 9V2.5M4.3 5.2 7 2.5l2.7 2.7"/><path d="M2 9.5v1.5a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V9.5"/></svg>',
-            images: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="1.5" y="2.5" width="11" height="9" rx="1.3"/><circle cx="4.7" cy="5.5" r="1"/><path d="M1.5 10 L5 6.5 L7.5 8.5 L10 5.5 L12.5 9"/></svg>',
-            save: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 2h7.5L12 4.5V12H2z"/><path d="M4.5 2v3h4V2"/><rect x="4.5" y="7.5" width="5" height="3.5"/></svg>',
-            expt: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="1.5" y="2.5" width="11" height="9" rx="1.3"/><path d="M1.5 10 L5 6.5 L7.5 8.5 L10 5.5 L12.5 9"/><circle cx="4.7" cy="5.5" r="1"/></svg>',
-            download: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M7 2v6.5M4.3 5.8 7 8.5l2.7-2.7"/><path d="M2 10v1.5a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V10"/></svg>'
-        };
-
-        var openDeviceInput = $('peOpenDeviceInput');
-
-        $('peOpen').addEventListener('click', function () {
-            T.menu(this, [
-                {
-                    label: 'Open from server…', icon: ICON.server, onClick: function () {
-                        ao_module_openFileSelector('_ptPickPdf', 'user:/', 'file', false, { filter: ['pdf'] });
-                    }
-                },
-                {
-                    label: 'Open from this device…', icon: ICON.device, onClick: function () {
-                        openDeviceInput.value = '';
-                        openDeviceInput.click();
-                    }
-                },
-                { separator: true },
-                { label: 'Create from images…', icon: ICON.images, onClick: function () { T.openImagesToPdf(); } }
-            ]);
-        });
-
-        openDeviceInput.addEventListener('change', function () {
-            if (!this.files || !this.files.length) { return; }
-            var f = this.files[0];
-            f.arrayBuffer().then(function (buf) {
-                openBytes(new Uint8Array(buf), f.name, null);
-            });
-        });
-
-        $('peAddText').addEventListener('click', function () {
-            if (!canvas) { return; }
-            addOverlay({
-                type: 'text', t: 'Double-click to edit', fx: 0.12, fy: 0.12,
-                fontFrac: 24 / canvas.height, color: $('peColor').value || '#d0021b'
-            });
-        });
-
-        $('peAddImg').addEventListener('click', function () {
-            ao_module_openFileSelector('_ptPickImg', 'user:/', 'file', false,
-                { filter: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'] });
-        });
-
-        var uploadInput = $('peUploadInput');
-        $('peUpload').addEventListener('click', function () {
-            uploadInput.value = '';
-            uploadInput.click();
-        });
-        uploadInput.addEventListener('change', function () {
-            if (!this.files || !this.files.length) { return; }
-            var reader = new FileReader();
-            reader.onload = function (ev) { placeImageFromSrc(ev.target.result); };
-            reader.readAsDataURL(this.files[0]);
-        });
-
-        // Keep the button's own events off the document closer below, so clicking
-        // the icon (the event target is the inner <svg>) toggles rather than closes.
-        $('peAddStamp').addEventListener('mousedown', function (e) { e.stopPropagation(); });
-        $('peAddStamp').addEventListener('click', function (e) {
-            e.stopPropagation();
-            if (stampMenu.classList.contains('show')) {
-                stampMenu.classList.remove('show');
-                return;
-            }
-            openStampMenu(this);
-        });
-
-        document.addEventListener('mousedown', function (e) {
-            if (!stampMenu.contains(e.target)) { stampMenu.classList.remove('show'); }
-        });
-
-        $('pePrev').addEventListener('click', function () {
-            if (doc.page > 1) { doc.page--; renderPage(doc.page); }
-        });
-        $('peNext').addEventListener('click', function () {
-            if (doc.page < doc.num) { doc.page++; renderPage(doc.page); }
-        });
-
-        zoomEl.addEventListener('change', function () {
-            zoom = this.value === 'fit' ? 'fit' : parseFloat(this.value);
-            if (doc.pdf) { renderPage(doc.page); }
-        });
-
-        $('peFontSize').addEventListener('input', function () {
-            $('peFontVal').textContent = this.value + 'px';
-            if (sel && sel.o.type === 'text') {
-                sel.o.fontFrac = parseInt(this.value, 10) / canvas.height;
-                sel.el.style.fontSize = this.value + 'px';
-            }
-        });
-        $('peColor').addEventListener('input', function () {
-            if (sel && sel.o.type === 'text') {
-                sel.o.color = this.value;
-                sel.el.style.color = this.value;
-            }
-        });
-
-        $('peSave').addEventListener('click', save);
-        $('peSaveMenu').addEventListener('click', function () {
-            T.menu(this, [
-                { label: 'Save…', icon: ICON.save, onClick: save },
-                { label: 'Download to this device', icon: ICON.download, onClick: downloadPdf },
-                { separator: true },
-                {
-                    label: 'Export pages as images…', icon: ICON.expt,
-                    onClick: function () { T.openExportImages(doc); }
-                }
-            ]);
-        });
-
-        /* ── Drag and drop: File Manager items and OS files ── */
-        ['dragenter', 'dragover'].forEach(function (ev) {
-            stageEl.addEventListener(ev, function (e) {
-                e.preventDefault();
-                stageEl.classList.add('dragover');
-            });
-        });
-        stageEl.addEventListener('dragleave', function (e) {
-            if (e.relatedTarget && stageEl.contains(e.relatedTarget)) { return; }
-            stageEl.classList.remove('dragover');
-        });
-        stageEl.addEventListener('drop', function (e) {
-            e.preventDefault();
-            stageEl.classList.remove('dragover');
-
-            // Dropped from the OS
-            if (e.dataTransfer.files && e.dataTransfer.files.length) {
-                var f = e.dataTransfer.files[0];
-                if (!/\.pdf$/i.test(f.name)) { T.toast('Only PDF files can be opened here.', true); return; }
-                f.arrayBuffer().then(function (buf) {
-                    openBytes(new Uint8Array(buf), f.name, null);
-                });
-                return;
-            }
-
-            // Dropped from the ArozOS File Manager
-            var info = null;
-            try { info = ao_module_utils.getDropFileInfo(e); } catch (err) { info = null; }
-            if (info && info.length) {
-                if (!/\.pdf$/i.test(info[0].filename)) {
-                    T.toast('Only PDF files can be opened here.', true);
-                    return;
-                }
-                openPdf(info[0].filepath, info[0].filename);
-            }
-        });
-
-        // Re-fit on resize (Fit mode only)
-        new ResizeObserver(function () {
-            if (!doc.pdf || zoom !== 'fit') { return; }
-            clearTimeout(resizeTimer);
-            resizeTimer = setTimeout(function () { if (doc.pdf) { renderPage(doc.page); } }, 120);
-        }).observe(stageEl);
-
-        window._ptPickPdf = function (files) {
-            if (!files || !files.length) { return; }
-            openPdf(files[0].filepath, files[0].filename);
-        };
-        window._ptPickImg = function (files) {
-            if (!files || !files.length) { return; }
-            placeImageFromSrc(T.mediaUrl(files[0].filepath));
-        };
-
-        // Opened with a file (embedded mode or "open with")
-        var input = ao_module_loadInputFiles();
-        if (input && input.length) {
-            openPdf(input[0].filepath, input[0].filename);
-        }
-    }
-
-    if (document.readyState === 'loading') {
-        document.addEventListener('DOMContentLoaded', boot);
-    } else {
-        boot();
-    }
-
-})(window.PDFTool);

Разница между файлами не показана из-за своего большого размера
+ 0 - 14
src/web/PDF Tool/lib/pdf-lib.min.js


Некоторые файлы не были показаны из-за большого количества измененных файлов