gutterpress 0.9.0-alpha.1 → 0.9.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/api/index.js +1 -1
  2. package/dist/{audit-k16v3n98.js → audit-nhn2pjz3.js} +3 -3
  3. package/dist/{build-8tqr4gbb.js → build-san7fv2z.js} +3 -3
  4. package/dist/{cli-rkqxbnkq.js → cli-e5zhb0xs.js} +1 -1
  5. package/dist/{cli-yp0d2hp8.js → cli-k4bd06sd.js} +377 -78
  6. package/dist/{cli-v2dze8ja.js → cli-najycadg.js} +1 -1
  7. package/dist/cli.js +15 -15
  8. package/dist/{doctor-57czxy3q.js → doctor-hrk0kxxz.js} +2 -2
  9. package/dist/{index-m3pa4wyf.js → index-bynn850m.js} +379 -80
  10. package/dist/index.js +1 -1
  11. package/dist/lib/markdown/assemble.d.ts +4 -6
  12. package/dist/lib/markdown/chapter-id.d.ts +1 -1
  13. package/dist/lib/markdown/index.d.ts +1 -1
  14. package/dist/{lint-4sq0dvf6.js → lint-96j9hrj4.js} +3 -3
  15. package/dist/{new-f2nmyr5b.js → new-8p38wavc.js} +3 -3
  16. package/dist/{pagedjs-interface-80g3xa8p.js → pagedjs-interface-qxvzgwd7.js} +92 -33
  17. package/dist/{plugin-xskq3dtx.js → plugin-ees6nhkc.js} +3 -3
  18. package/dist/{preflight-epcffags.js → preflight-1q6c2edh.js} +3 -3
  19. package/dist/preview/file-watcher.d.ts +39 -17
  20. package/dist/preview/http-server.d.ts +5 -2
  21. package/dist/preview/server-context.d.ts +2 -0
  22. package/dist/preview-shell-6dqexx1m.js +581 -0
  23. package/dist/{preview-xf5dktz2.js → preview-y5a2zen1.js} +3 -3
  24. package/dist/{publish-97vdwq31.js → publish-rm9yb3wh.js} +3 -3
  25. package/dist/render.js +10 -19
  26. package/dist/{repair-cz4z4hkg.js → repair-zgq7q2g6.js} +3 -3
  27. package/dist/server.d.ts +2 -0
  28. package/dist/{validate-swzejnd8.js → validate-nr0xa6sa.js} +3 -3
  29. package/package.json +1 -1
  30. package/dist/preview-shell-rghtfmc8.js +0 -155
package/dist/server.d.ts CHANGED
@@ -16,6 +16,8 @@ export interface PreviewServerHandle {
16
16
  stop: () => Promise<void>;
17
17
  /** Switch the watched directory and regenerate HTML. */
18
18
  restart: (newInputPath: string) => Promise<void>;
19
+ /** Rebuild immediately after a host-managed write has fully settled. */
20
+ notifySettledWrite: (filePath: string, writtenContent: string) => void;
19
21
  }
20
22
  export interface StartPreviewServerOptions extends PreviewServerOptions {
21
23
  /**
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  executeAndReport
3
- } from "./cli-yp0d2hp8.js";
3
+ } from "./cli-k4bd06sd.js";
4
4
  import {
5
5
  log
6
- } from "./cli-v2dze8ja.js";
6
+ } from "./cli-najycadg.js";
7
7
  import {
8
8
  EXIT_CODES,
9
9
  UsageError,
10
10
  rejectExtraPositionals,
11
11
  rejectUnknownFlags
12
- } from "./cli-rkqxbnkq.js";
12
+ } from "./cli-e5zhb0xs.js";
13
13
  import"./cli-yzrh708h.js";
14
14
  import"./cli-wchtvxvw.js";
15
15
  import"./cli-yja077f6.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gutterpress",
3
- "version": "0.9.0-alpha.1",
3
+ "version": "0.9.0-alpha.2",
4
4
  "description": "Markdown-to-PDF converter for professional print layout using Paged.js and Ghostscript.",
5
5
  "author": "itlackey",
6
6
  "license": "MPL-2.0",
@@ -1,155 +0,0 @@
1
- // Gutterpress preview shell controller (shared by the CLI preview and Electron).
2
- // Every source change takes one correctness-first path: paginate a fresh hidden
3
- // full document, then swap it in without flashing unpaginated content.
4
- //
5
- // TRANSPORT IS ABSTRACTED: change events arrive through connectChanges(), which
6
- // uses WebSocket by default but honors window.__GUTTERPRESS_CHANGE_SOURCE so an Electron
7
- // host can feed the same full-reload signal over IPC.
8
- (function () {
9
- 'use strict';
10
- var active = document.getElementById('gutterpress-active');
11
- var building = null;
12
- if (!active) return;
13
-
14
- // Transparent bridge relay: forward host-toolbar commands to the active book
15
- // iframe and relay its replies/events back to the host.
16
- window.addEventListener('message', function (e) {
17
- try {
18
- if (window.parent !== window && e.source === window.parent) {
19
- if (active && active.contentWindow) active.contentWindow.postMessage(e.data, '*');
20
- } else if (active && e.source === active.contentWindow && window.parent !== window) {
21
- window.parent.postMessage(e.data, '*');
22
- }
23
- } catch (_) {}
24
- });
25
-
26
- function fdoc(f) { try { return f.contentDocument; } catch (_) { return null; } }
27
- function fwin(f) { try { return f.contentWindow; } catch (_) { return null; } }
28
- function chapterOf(el) {
29
- var chapter = el.closest && el.closest('[data-chapter-src]');
30
- return chapter ? chapter.getAttribute('data-chapter-src') : null;
31
- }
32
- function blocksInChapter(d, chapter) {
33
- var all = d.querySelectorAll('[data-source-line]');
34
- if (!chapter) return all;
35
- var matched = [];
36
- for (var i = 0; i < all.length; i++) {
37
- if (chapterOf(all[i]) === chapter) matched.push(all[i]);
38
- }
39
- return matched;
40
- }
41
-
42
- // data-source-line resets per source file, so preserve both chapter and line.
43
- function capture(f) {
44
- var d = fdoc(f); if (!d) return null;
45
- var els = d.querySelectorAll('[data-source-line]'), best = null, bestTop = -Infinity;
46
- for (var i = 0; i < els.length; i++) {
47
- var r = els[i].getBoundingClientRect();
48
- if (r.bottom < 0 || r.height === 0) continue;
49
- if (r.top <= 80 && r.top > bestTop) { bestTop = r.top; best = els[i]; }
50
- }
51
- if (!best) {
52
- for (var j = 0; j < els.length; j++) {
53
- var rr = els[j].getBoundingClientRect();
54
- if (rr.bottom > 0 && rr.height > 0) { best = els[j]; break; }
55
- }
56
- }
57
- if (!best) return null;
58
- return {
59
- chapter: chapterOf(best),
60
- line: best.getAttribute('data-source-line'),
61
- offset: best.getBoundingClientRect().top
62
- };
63
- }
64
-
65
- function restore(f, anchor) {
66
- if (!anchor) return;
67
- var w = fwin(f), d = fdoc(f); if (!w || !d) return;
68
- var els = blocksInChapter(d, anchor.chapter);
69
- var wanted = parseInt(anchor.line, 10), el = null, bestDiff = Infinity;
70
- for (var i = 0; i < els.length; i++) {
71
- var line = parseInt(els[i].getAttribute('data-source-line'), 10);
72
- if (String(els[i].getAttribute('data-source-line')) === String(anchor.line)) {
73
- el = els[i];
74
- break;
75
- }
76
- var diff = Math.abs(line - wanted);
77
- if (diff < bestDiff) { bestDiff = diff; el = els[i]; }
78
- }
79
- if (el) w.scrollBy(0, el.getBoundingClientRect().top - anchor.offset);
80
- }
81
-
82
- function onReady(f, callback) {
83
- var w = fwin(f), d = fdoc(f); if (!w || !d) { callback(); return; }
84
- var hasPaged = !!d.querySelector('script[src*="paged.polyfill"], script[src*="pagedjs"]');
85
- if (hasPaged) {
86
- var done = false;
87
- var finish = function () { if (!done) { done = true; callback(); } };
88
- w.addEventListener('renderingComplete', finish, { once: true });
89
- setTimeout(finish, 180000);
90
- return;
91
- }
92
- var attempts = 0;
93
- (function poll() {
94
- var current = fdoc(f);
95
- if (current && current.querySelectorAll('.pagedjs_page').length > 0) { callback(); return; }
96
- if (attempts++ < 800) setTimeout(poll, 25); else callback();
97
- })();
98
- }
99
-
100
- function swap() {
101
- // A newer reload invalidates any older hidden pagination. Its callback also
102
- // checks identity before swapping, so stale work can never win a race.
103
- if (building && building.parentNode) building.parentNode.removeChild(building);
104
- building = null;
105
-
106
- var frame = document.createElement('iframe');
107
- frame.style.visibility = 'hidden';
108
- frame.setAttribute('aria-hidden', 'true');
109
- frame.src = '/book.html?gutterpressshell=1&bust=' + Date.now();
110
- building = frame;
111
-
112
- var finished = false;
113
- function finish() {
114
- if (finished || building !== frame) return;
115
- finished = true;
116
- // Capture at swap time, not rebuild start: the visible frame stays usable
117
- // while a long book paginates and the user may scroll during that work.
118
- var anchor = capture(active);
119
- restore(frame, anchor);
120
- frame.style.visibility = 'visible';
121
- frame.removeAttribute('aria-hidden');
122
- var old = active;
123
- active = frame;
124
- building = null;
125
- requestAnimationFrame(function () {
126
- requestAnimationFrame(function () {
127
- if (old && old.parentNode) old.parentNode.removeChild(old);
128
- });
129
- });
130
- }
131
-
132
- frame.addEventListener('load', function () { onReady(frame, finish); });
133
- document.body.appendChild(frame);
134
- }
135
-
136
- function connectChanges(onMessage) {
137
- var source = window.__GUTTERPRESS_CHANGE_SOURCE;
138
- if (source && typeof source.subscribe === 'function') return source.subscribe(onMessage);
139
- var wsPath = window.__GUTTERPRESS_HMR || '/__gutterpress-hmr';
140
- var ws = new WebSocket(location.origin.replace(/^http/, 'ws') + wsPath);
141
- ws.onmessage = function (event) {
142
- var message;
143
- try { message = JSON.parse(event.data); } catch (_) { return; }
144
- onMessage(message);
145
- };
146
- return function () { try { ws.close(); } catch (_) {} };
147
- }
148
-
149
- connectChanges(function (message) {
150
- if (!message || !message.type) return;
151
- // Accept legacy content-update producers, but never perform an isolated
152
- // chapter splice: a changed boundary can affect every following page.
153
- if (message.type === 'full-reload' || message.type === 'content-update') swap();
154
- });
155
- })();