@windoc/core 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/aliansyahFirdaus/windoc/main/docs/static/img/logo-text-white.png#gh-light-mode-only" alt="Windoc" height="120">
3
+ <img src="https://raw.githubusercontent.com/aliansyahFirdaus/windoc/main/docs/static/img/logo-text-black.png#gh-dark-mode-only" alt="Windoc" height="120">
4
+ </div>
5
+
6
+ # @windoc/core
7
+
8
+ Canvas-based document editor engine for the web. Renders documents using HTML5 Canvas with pixel-perfect pagination, headers, footers, watermarks, and print support.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ yarn add @windoc/core
14
+ # or
15
+ npm install @windoc/core
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```typescript
21
+ import Editor from '@windoc/core'
22
+ import '@windoc/core/style.css'
23
+
24
+ const container = document.getElementById('editor')
25
+
26
+ const editor = new Editor(container, {
27
+ main: [
28
+ { value: 'Hello, Windoc!' }
29
+ ]
30
+ }, {
31
+ margins: [40, 40, 40, 40],
32
+ watermark: { data: '', size: 120 },
33
+ placeholder: { data: 'Start typing...' },
34
+ })
35
+ ```
36
+
37
+ ## Features
38
+
39
+ - **Canvas Rendering** — High-performance rendering via HTML5 Canvas
40
+ - **Pagination** — Automatic page breaking with configurable page sizes (A4, Letter, etc.)
41
+ - **Rich Text** — Bold, italic, underline, strikeout, color, highlight, fonts, font sizes
42
+ - **Tables** — Full table support with merge/split cells, borders, row/column operations
43
+ - **Images** — Inline images with resize, rotate, and alignment
44
+ - **Headers & Footers** — Per-page headers, footers, and page numbers
45
+ - **Watermarks** — Configurable text watermarks
46
+ - **Lists** — Ordered and unordered lists
47
+ - **Zones** — Document zones (header, body, footer) with visual tips
48
+ - **History** — Undo/redo with full state management
49
+ - **Keyboard Shortcuts** — Customizable shortcut registration
50
+ - **Context Menus** — Extensible right-click context menus
51
+ - **Print** — Native print support with accurate pagination
52
+ - **i18n** — Built-in internationalization (English, Chinese)
53
+ - **Plugins** — Plugin architecture for extensibility
54
+ - **Commands** — Comprehensive command API for programmatic control
55
+
56
+ ## API
57
+
58
+ ### Constructor
59
+
60
+ ```typescript
61
+ new Editor(container: HTMLElement, data: EditorData, options?: EditorOptions)
62
+ ```
63
+
64
+ ### EditorData
65
+
66
+ ```typescript
67
+ interface EditorData {
68
+ header?: IElement[] // Header elements
69
+ main: IElement[] // Body content elements
70
+ footer?: IElement[] // Footer elements
71
+ }
72
+ ```
73
+
74
+ ### Key Options
75
+
76
+ | Option | Type | Description |
77
+ |--------|------|-------------|
78
+ | `margins` | `number[]` | Page margins `[top, right, bottom, left]` |
79
+ | `watermark` | `object` | Watermark config `{ data, size, color, opacity }` |
80
+ | `header` | `object` | Header config `{ top, disabled }` |
81
+ | `footer` | `object` | Footer config `{ bottom, disabled, backgroundColor }` |
82
+ | `pageNumber` | `object` | Page number config `{ disabled, format, color, font, size }` |
83
+ | `placeholder` | `object` | Placeholder text `{ data }` |
84
+ | `zone` | `object` | Zone settings `{ tipDisabled }` |
85
+ | `maskMargin` | `number[]` | Mask margin around pages |
86
+
87
+ ### Commands
88
+
89
+ Access via `editor.command`:
90
+
91
+ ```typescript
92
+ editor.command.executeSetValue(data) // Set document content
93
+ editor.command.getValue() // Get document data
94
+ editor.command.executePrint() // Print document
95
+ editor.command.executeUndo() // Undo
96
+ editor.command.executeRedo() // Redo
97
+ editor.command.executeBold() // Toggle bold
98
+ editor.command.executeItalic() // Toggle italic
99
+ editor.command.executeInsertTable(rows, cols) // Insert table
100
+ editor.command.getWordCount() // Get word count (async)
101
+ ```
102
+
103
+ ### Listeners
104
+
105
+ ```typescript
106
+ editor.listener.rangeStyleChange = (payload) => { /* selection style changed */ }
107
+ editor.listener.contentChange = () => { /* content changed */ }
108
+ editor.listener.pageSizeChange = (count) => { /* page count changed */ }
109
+ editor.listener.intersectionPageNoChange = (pageNo) => { /* visible page changed */ }
110
+ editor.listener.pageScaleChange = (scale) => { /* zoom level changed */ }
111
+ ```
112
+
113
+ ### Shortcuts
114
+
115
+ ```typescript
116
+ editor.register.shortcutList([
117
+ { key: KeyMap.P, mod: true, isGlobal: true, callback: (cmd) => cmd.executePrint() },
118
+ ])
119
+ ```
120
+
121
+ ### Context Menus
122
+
123
+ ```typescript
124
+ editor.register.contextMenuList([
125
+ {
126
+ name: 'My Action',
127
+ icon: 'custom-icon',
128
+ when: (payload) => !payload.isReadonly,
129
+ callback: (command) => { /* do something */ },
130
+ },
131
+ ])
132
+ ```
133
+
134
+ ## License
135
+
136
+ MIT
package/dist/index.js CHANGED
@@ -467,9 +467,6 @@ function scrollIntoView(container, selected) {
467
467
  }
468
468
  }
469
469
 
470
- // src/core/cursor/Cursor.ts
471
- var import_process = require("process");
472
-
473
470
  // src/dataset/constant/Editor.ts
474
471
  var EDITOR_COMPONENT = "editor-component";
475
472
  var EDITOR_PREFIX = "ce";
@@ -6415,6 +6412,7 @@ var CursorAgent = class {
6415
6412
  };
6416
6413
 
6417
6414
  // src/core/cursor/Cursor.ts
6415
+ var nextTick2 = (fn) => Promise.resolve().then(fn);
6418
6416
  var Cursor = class {
6419
6417
  constructor(draw, canvasEvent) {
6420
6418
  this.ANIMATION_CLASS = `${EDITOR_PREFIX}-cursor--animation`;
@@ -6551,7 +6549,7 @@ var Cursor = class {
6551
6549
  } else {
6552
6550
  this._clearBlinkTimeout();
6553
6551
  }
6554
- (0, import_process.nextTick)(() => {
6552
+ nextTick2(() => {
6555
6553
  this.moveCursorToVisible({
6556
6554
  cursorPosition,
6557
6555
  direction: parseInt(oldTop) > cursorTop ? "top" /* UP */ : "down" /* DOWN */
@@ -12387,6 +12385,7 @@ var HyperlinkParticle = class {
12387
12385
  _createHyperlinkPopupDom() {
12388
12386
  const hyperlinkPopupContainer = document.createElement("div");
12389
12387
  hyperlinkPopupContainer.classList.add(`${EDITOR_PREFIX}-hyperlink-popup`);
12388
+ hyperlinkPopupContainer.style.display = "none";
12390
12389
  const hyperlinkDom = document.createElement("a");
12391
12390
  hyperlinkDom.target = "_blank";
12392
12391
  hyperlinkDom.rel = "noopener";
@@ -16548,6 +16547,7 @@ var Previewer = class {
16548
16547
  resizerImageContainer.classList.add(`${EDITOR_PREFIX}-resizer-image`);
16549
16548
  resizerImageContainer.style.display = "none";
16550
16549
  const resizerImage = document.createElement("img");
16550
+ resizerImage.alt = "";
16551
16551
  resizerImageContainer.append(resizerImage);
16552
16552
  this.container.append(resizerImageContainer);
16553
16553
  return {