@twip/web 0.0.0 → 0.1.0-alpha.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/LICENSE +202 -0
- package/dist/AccessibleNode.d.ts +51 -0
- package/dist/AccessibleNode.mjs +177 -0
- package/dist/Alignment.d.ts +38 -0
- package/dist/Alignment.mjs +90 -0
- package/dist/BorderEdges.d.ts +50 -0
- package/dist/BorderEdges.mjs +114 -0
- package/dist/BorderStyle.d.ts +27 -0
- package/dist/BorderStyle.mjs +81 -0
- package/dist/Bytes.d.ts +19 -0
- package/dist/Bytes.mjs +76 -0
- package/dist/CaretPosition.d.ts +34 -0
- package/dist/CaretPosition.mjs +148 -0
- package/dist/CellAlignment.d.ts +25 -0
- package/dist/CellAlignment.mjs +75 -0
- package/dist/CellShift.d.ts +30 -0
- package/dist/CellShift.mjs +78 -0
- package/dist/Clipboard.d.ts +22 -0
- package/dist/Clipboard.mjs +90 -0
- package/dist/ColumnSide.d.ts +24 -0
- package/dist/ColumnSide.mjs +72 -0
- package/dist/ControlKind.d.ts +28 -0
- package/dist/ControlKind.mjs +84 -0
- package/dist/ControlLock.d.ts +42 -0
- package/dist/ControlLock.mjs +96 -0
- package/dist/DocumentStatus.d.ts +34 -0
- package/dist/DocumentStatus.mjs +148 -0
- package/dist/Editor.d.ts +773 -0
- package/dist/Editor.mjs +2269 -0
- package/dist/EditorMode.d.ts +34 -0
- package/dist/EditorMode.mjs +84 -0
- package/dist/Element.d.ts +57 -0
- package/dist/Element.mjs +201 -0
- package/dist/ElementKind.d.ts +28 -0
- package/dist/ElementKind.mjs +78 -0
- package/dist/ElementList.d.ts +20 -0
- package/dist/ElementList.mjs +71 -0
- package/dist/ElementText.d.ts +34 -0
- package/dist/ElementText.mjs +84 -0
- package/dist/Event.d.ts +45 -0
- package/dist/Event.mjs +159 -0
- package/dist/EventKind.d.ts +39 -0
- package/dist/EventKind.mjs +93 -0
- package/dist/EventList.d.ts +20 -0
- package/dist/EventList.mjs +71 -0
- package/dist/Fonts.d.ts +29 -0
- package/dist/Fonts.mjs +107 -0
- package/dist/Highlight.d.ts +41 -0
- package/dist/Highlight.mjs +117 -0
- package/dist/MarginPreset.d.ts +38 -0
- package/dist/MarginPreset.mjs +90 -0
- package/dist/MarkSeverity.d.ts +25 -0
- package/dist/MarkSeverity.mjs +75 -0
- package/dist/Modifiers.d.ts +34 -0
- package/dist/Modifiers.mjs +148 -0
- package/dist/OpenError.d.ts +30 -0
- package/dist/OpenError.mjs +78 -0
- package/dist/Orientation.d.ts +30 -0
- package/dist/Orientation.mjs +78 -0
- package/dist/PageNumber.d.ts +34 -0
- package/dist/PageNumber.mjs +84 -0
- package/dist/PaperSize.d.ts +50 -0
- package/dist/PaperSize.mjs +108 -0
- package/dist/ParagraphBorders.d.ts +34 -0
- package/dist/ParagraphBorders.mjs +84 -0
- package/dist/PictureWrap.d.ts +34 -0
- package/dist/PictureWrap.mjs +90 -0
- package/dist/PointerKind.d.ts +23 -0
- package/dist/PointerKind.mjs +75 -0
- package/dist/Rect.d.ts +34 -0
- package/dist/Rect.mjs +148 -0
- package/dist/Request.d.ts +55 -0
- package/dist/Request.mjs +207 -0
- package/dist/RequestKind.d.ts +45 -0
- package/dist/RequestKind.mjs +105 -0
- package/dist/RequestList.d.ts +20 -0
- package/dist/RequestList.mjs +71 -0
- package/dist/RowHeightRule.d.ts +34 -0
- package/dist/RowHeightRule.mjs +84 -0
- package/dist/RowSide.d.ts +24 -0
- package/dist/RowSide.mjs +72 -0
- package/dist/SaveError.d.ts +24 -0
- package/dist/SaveError.mjs +72 -0
- package/dist/SelectionInfo.d.ts +39 -0
- package/dist/SelectionInfo.mjs +166 -0
- package/dist/SelectionKind.d.ts +37 -0
- package/dist/SelectionKind.mjs +93 -0
- package/dist/THIRD-PARTY-NOTICES.md +4475 -0
- package/dist/TableAlignment.d.ts +25 -0
- package/dist/TableAlignment.mjs +75 -0
- package/dist/TableSelection.d.ts +38 -0
- package/dist/TableSelection.mjs +90 -0
- package/dist/TableWidthUnit.d.ts +31 -0
- package/dist/TableWidthUnit.mjs +81 -0
- package/dist/TextUnit.d.ts +25 -0
- package/dist/TextUnit.mjs +75 -0
- package/dist/diplomat-runtime.d.ts +15 -0
- package/dist/diplomat-runtime.mjs +786 -0
- package/dist/diplomat-wasm.mjs +18 -0
- package/dist/gpu.d.ts +15 -0
- package/dist/gpu.mjs +42 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.mjs +101 -0
- package/dist/twip-wasm.js +2 -0
- package/dist/twip_wasm.wasm +0 -0
- package/package.json +18 -4
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Replaces Diplomat's loader (which instantiates a bare wasm32-unknown-unknown module): the engine is an emscripten
|
|
2
|
+
// module, so its exports live on the emscripten Module as `_name`, and its memory can grow. Copied over the
|
|
3
|
+
// generated diplomat-wasm.mjs by `moon run web:generate`.
|
|
4
|
+
import createTwip from './twip-wasm.js';
|
|
5
|
+
|
|
6
|
+
const module = await createTwip();
|
|
7
|
+
|
|
8
|
+
/** The emscripten module itself: its `WebGPU` and `GL` helpers import browser GPU objects (gpu.mjs). */
|
|
9
|
+
export const emscripten = module;
|
|
10
|
+
|
|
11
|
+
const wasm = new Proxy({}, {
|
|
12
|
+
get(_, name) {
|
|
13
|
+
if (name === 'memory') return { get buffer() { return module.HEAPU8.buffer; } };
|
|
14
|
+
return module[`_${String(name)}`];
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export default wasm;
|
package/dist/gpu.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Editor } from './Editor';
|
|
2
|
+
|
|
3
|
+
export interface WebGpuTarget { canvas: HTMLCanvasElement; context: GPUCanvasContext; bgra: boolean }
|
|
4
|
+
export interface WebGlTarget { canvas: HTMLCanvasElement; handle: number }
|
|
5
|
+
|
|
6
|
+
/** Adopts a GPUDevice for every editor; false if the engine can't use it (paint with WebGL instead). */
|
|
7
|
+
export function attachWebGpu(device: GPUDevice): boolean;
|
|
8
|
+
/** Configures `canvas` for WebGPU painting with `device`. */
|
|
9
|
+
export function webGpuTarget(canvas: HTMLCanvasElement, device: GPUDevice): WebGpuTarget;
|
|
10
|
+
/** Paints `editor` into the target's current texture; the page stack's top-left at (`originX`, `originY`) CSS px. */
|
|
11
|
+
export function paintWebGpu(editor: Editor, target: WebGpuTarget, originX: number, originY: number, dpr?: number): boolean;
|
|
12
|
+
/** Creates a WebGL 2 context on `canvas` for `editor` (one per canvas). */
|
|
13
|
+
export function webGlTarget(editor: Editor, canvas: HTMLCanvasElement): WebGlTarget;
|
|
14
|
+
/** Paints `editor` into its WebGL canvas; the page stack's top-left at (`originX`, `originY`) CSS px. */
|
|
15
|
+
export function paintWebGl(editor: Editor, target: WebGlTarget, originX: number, originY: number, dpr?: number): boolean;
|
package/dist/gpu.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Browser GPU painting: imports the page's WebGPU device and canvas textures, or a WebGL 2 context, into the engine
|
|
2
|
+
// module and paints an editor through them. Hosts call these instead of the raw handle methods on Editor.
|
|
3
|
+
import { emscripten } from './diplomat-wasm.mjs';
|
|
4
|
+
import { Editor } from './Editor.mjs';
|
|
5
|
+
|
|
6
|
+
/** Adopts a GPUDevice for every editor; false if the engine can't use it (paint with WebGL instead). */
|
|
7
|
+
export function attachWebGpu(device) {
|
|
8
|
+
const instance = Editor.webgpuInstance();
|
|
9
|
+
const { WebGPU } = emscripten;
|
|
10
|
+
return Editor.attachWebgpu(instance, WebGPU.importJsDevice(device, instance), WebGPU.importJsQueue(device.queue, instance));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Configures `canvas` for WebGPU painting with `device`; pass the result to `paintWebGpu`. */
|
|
14
|
+
export function webGpuTarget(canvas, device) {
|
|
15
|
+
const context = canvas.getContext('webgpu');
|
|
16
|
+
const format = navigator.gpu.getPreferredCanvasFormat();
|
|
17
|
+
// COPY_SRC | COPY_DST | TEXTURE_BINDING | RENDER_ATTACHMENT: what Graphite needs of the canvas texture.
|
|
18
|
+
context.configure({ device, format, alphaMode: 'premultiplied', usage: 0x01 | 0x02 | 0x04 | 0x10 });
|
|
19
|
+
return { canvas, context, bgra: format === 'bgra8unorm' };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Paints `editor` into the target's current texture; the page stack's top-left at (`originX`, `originY`) CSS px. */
|
|
23
|
+
export function paintWebGpu(editor, target, originX, originY, dpr = globalThis.devicePixelRatio ?? 1) {
|
|
24
|
+
const texture = emscripten.WebGPU.importJsTexture(target.context.getCurrentTexture());
|
|
25
|
+
return editor.paintWebgpu(texture, target.bgra, originX, originY, target.canvas.height, dpr);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Creates a WebGL 2 context on `canvas` for `editor` (one per canvas); pass the result to `paintWebGl`. */
|
|
29
|
+
export function webGlTarget(editor, canvas) {
|
|
30
|
+
const { GL } = emscripten;
|
|
31
|
+
const handle = GL.createContext(canvas, { majorVersion: 2, minorVersion: 0, alpha: 1, depth: 0, stencil: 8, antialias: 0, premultipliedAlpha: 1 });
|
|
32
|
+
if (!handle) throw new Error('WebGL 2 is unavailable');
|
|
33
|
+
GL.makeContextCurrent(handle);
|
|
34
|
+
if (!editor.attachWebgl()) throw new Error('the engine could not use the WebGL context');
|
|
35
|
+
return { canvas, handle };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Paints `editor` into its WebGL canvas; the page stack's top-left at (`originX`, `originY`) CSS px. */
|
|
39
|
+
export function paintWebGl(editor, target, originX, originY, dpr = globalThis.devicePixelRatio ?? 1) {
|
|
40
|
+
emscripten.GL.makeContextCurrent(target.handle);
|
|
41
|
+
return editor.paintWebgl(originX, originY, target.canvas.width, target.canvas.height, dpr);
|
|
42
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
|
|
2
|
+
export { codepoint } from './diplomat-runtime';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export { CaretPosition, CaretPosition_obj } from "./CaretPosition"
|
|
6
|
+
|
|
7
|
+
export { DocumentStatus, DocumentStatus_obj } from "./DocumentStatus"
|
|
8
|
+
|
|
9
|
+
export { Modifiers, Modifiers_obj } from "./Modifiers"
|
|
10
|
+
|
|
11
|
+
export { Rect, Rect_obj } from "./Rect"
|
|
12
|
+
|
|
13
|
+
export { SelectionInfo, SelectionInfo_obj } from "./SelectionInfo"
|
|
14
|
+
|
|
15
|
+
export { AccessibleNode } from "./AccessibleNode"
|
|
16
|
+
|
|
17
|
+
export { Bytes } from "./Bytes"
|
|
18
|
+
|
|
19
|
+
export { Clipboard } from "./Clipboard"
|
|
20
|
+
|
|
21
|
+
export { Editor } from "./Editor"
|
|
22
|
+
|
|
23
|
+
export { Element } from "./Element"
|
|
24
|
+
|
|
25
|
+
export { ElementList } from "./ElementList"
|
|
26
|
+
|
|
27
|
+
export { Event } from "./Event"
|
|
28
|
+
|
|
29
|
+
export { EventList } from "./EventList"
|
|
30
|
+
|
|
31
|
+
export { Fonts } from "./Fonts"
|
|
32
|
+
|
|
33
|
+
export { Request } from "./Request"
|
|
34
|
+
|
|
35
|
+
export { RequestList } from "./RequestList"
|
|
36
|
+
|
|
37
|
+
export { Alignment } from "./Alignment"
|
|
38
|
+
|
|
39
|
+
export { BorderEdges } from "./BorderEdges"
|
|
40
|
+
|
|
41
|
+
export { BorderStyle } from "./BorderStyle"
|
|
42
|
+
|
|
43
|
+
export { CellAlignment } from "./CellAlignment"
|
|
44
|
+
|
|
45
|
+
export { CellShift } from "./CellShift"
|
|
46
|
+
|
|
47
|
+
export { ColumnSide } from "./ColumnSide"
|
|
48
|
+
|
|
49
|
+
export { ControlKind } from "./ControlKind"
|
|
50
|
+
|
|
51
|
+
export { ControlLock } from "./ControlLock"
|
|
52
|
+
|
|
53
|
+
export { EditorMode } from "./EditorMode"
|
|
54
|
+
|
|
55
|
+
export { ElementKind } from "./ElementKind"
|
|
56
|
+
|
|
57
|
+
export { ElementText } from "./ElementText"
|
|
58
|
+
|
|
59
|
+
export { EventKind } from "./EventKind"
|
|
60
|
+
|
|
61
|
+
export { Highlight } from "./Highlight"
|
|
62
|
+
|
|
63
|
+
export { MarginPreset } from "./MarginPreset"
|
|
64
|
+
|
|
65
|
+
export { MarkSeverity } from "./MarkSeverity"
|
|
66
|
+
|
|
67
|
+
export { OpenError } from "./OpenError"
|
|
68
|
+
|
|
69
|
+
export { Orientation } from "./Orientation"
|
|
70
|
+
|
|
71
|
+
export { PageNumber } from "./PageNumber"
|
|
72
|
+
|
|
73
|
+
export { PaperSize } from "./PaperSize"
|
|
74
|
+
|
|
75
|
+
export { ParagraphBorders } from "./ParagraphBorders"
|
|
76
|
+
|
|
77
|
+
export { PictureWrap } from "./PictureWrap"
|
|
78
|
+
|
|
79
|
+
export { PointerKind } from "./PointerKind"
|
|
80
|
+
|
|
81
|
+
export { RequestKind } from "./RequestKind"
|
|
82
|
+
|
|
83
|
+
export { RowHeightRule } from "./RowHeightRule"
|
|
84
|
+
|
|
85
|
+
export { RowSide } from "./RowSide"
|
|
86
|
+
|
|
87
|
+
export { SaveError } from "./SaveError"
|
|
88
|
+
|
|
89
|
+
export { SelectionKind } from "./SelectionKind"
|
|
90
|
+
|
|
91
|
+
export { TableAlignment } from "./TableAlignment"
|
|
92
|
+
|
|
93
|
+
export { TableSelection } from "./TableSelection"
|
|
94
|
+
|
|
95
|
+
export { TableWidthUnit } from "./TableWidthUnit"
|
|
96
|
+
|
|
97
|
+
export { TextUnit } from "./TextUnit"
|
|
98
|
+
export * from './gpu';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export { CaretPosition } from "./CaretPosition.mjs"
|
|
4
|
+
|
|
5
|
+
export { DocumentStatus } from "./DocumentStatus.mjs"
|
|
6
|
+
|
|
7
|
+
export { Modifiers } from "./Modifiers.mjs"
|
|
8
|
+
|
|
9
|
+
export { Rect } from "./Rect.mjs"
|
|
10
|
+
|
|
11
|
+
export { SelectionInfo } from "./SelectionInfo.mjs"
|
|
12
|
+
|
|
13
|
+
export { AccessibleNode } from "./AccessibleNode.mjs"
|
|
14
|
+
|
|
15
|
+
export { Bytes } from "./Bytes.mjs"
|
|
16
|
+
|
|
17
|
+
export { Clipboard } from "./Clipboard.mjs"
|
|
18
|
+
|
|
19
|
+
export { Editor } from "./Editor.mjs"
|
|
20
|
+
|
|
21
|
+
export { Element } from "./Element.mjs"
|
|
22
|
+
|
|
23
|
+
export { ElementList } from "./ElementList.mjs"
|
|
24
|
+
|
|
25
|
+
export { Event } from "./Event.mjs"
|
|
26
|
+
|
|
27
|
+
export { EventList } from "./EventList.mjs"
|
|
28
|
+
|
|
29
|
+
export { Fonts } from "./Fonts.mjs"
|
|
30
|
+
|
|
31
|
+
export { Request } from "./Request.mjs"
|
|
32
|
+
|
|
33
|
+
export { RequestList } from "./RequestList.mjs"
|
|
34
|
+
|
|
35
|
+
export { Alignment } from "./Alignment.mjs"
|
|
36
|
+
|
|
37
|
+
export { BorderEdges } from "./BorderEdges.mjs"
|
|
38
|
+
|
|
39
|
+
export { BorderStyle } from "./BorderStyle.mjs"
|
|
40
|
+
|
|
41
|
+
export { CellAlignment } from "./CellAlignment.mjs"
|
|
42
|
+
|
|
43
|
+
export { CellShift } from "./CellShift.mjs"
|
|
44
|
+
|
|
45
|
+
export { ColumnSide } from "./ColumnSide.mjs"
|
|
46
|
+
|
|
47
|
+
export { ControlKind } from "./ControlKind.mjs"
|
|
48
|
+
|
|
49
|
+
export { ControlLock } from "./ControlLock.mjs"
|
|
50
|
+
|
|
51
|
+
export { EditorMode } from "./EditorMode.mjs"
|
|
52
|
+
|
|
53
|
+
export { ElementKind } from "./ElementKind.mjs"
|
|
54
|
+
|
|
55
|
+
export { ElementText } from "./ElementText.mjs"
|
|
56
|
+
|
|
57
|
+
export { EventKind } from "./EventKind.mjs"
|
|
58
|
+
|
|
59
|
+
export { Highlight } from "./Highlight.mjs"
|
|
60
|
+
|
|
61
|
+
export { MarginPreset } from "./MarginPreset.mjs"
|
|
62
|
+
|
|
63
|
+
export { MarkSeverity } from "./MarkSeverity.mjs"
|
|
64
|
+
|
|
65
|
+
export { OpenError } from "./OpenError.mjs"
|
|
66
|
+
|
|
67
|
+
export { Orientation } from "./Orientation.mjs"
|
|
68
|
+
|
|
69
|
+
export { PageNumber } from "./PageNumber.mjs"
|
|
70
|
+
|
|
71
|
+
export { PaperSize } from "./PaperSize.mjs"
|
|
72
|
+
|
|
73
|
+
export { ParagraphBorders } from "./ParagraphBorders.mjs"
|
|
74
|
+
|
|
75
|
+
export { PictureWrap } from "./PictureWrap.mjs"
|
|
76
|
+
|
|
77
|
+
export { PointerKind } from "./PointerKind.mjs"
|
|
78
|
+
|
|
79
|
+
export { RequestKind } from "./RequestKind.mjs"
|
|
80
|
+
|
|
81
|
+
export { RowHeightRule } from "./RowHeightRule.mjs"
|
|
82
|
+
|
|
83
|
+
export { RowSide } from "./RowSide.mjs"
|
|
84
|
+
|
|
85
|
+
export { SaveError } from "./SaveError.mjs"
|
|
86
|
+
|
|
87
|
+
export { SelectionKind } from "./SelectionKind.mjs"
|
|
88
|
+
|
|
89
|
+
export { TableAlignment } from "./TableAlignment.mjs"
|
|
90
|
+
|
|
91
|
+
export { TableSelection } from "./TableSelection.mjs"
|
|
92
|
+
|
|
93
|
+
export { TableWidthUnit } from "./TableWidthUnit.mjs"
|
|
94
|
+
|
|
95
|
+
export { TextUnit } from "./TextUnit.mjs"
|
|
96
|
+
|
|
97
|
+
import wasm from "./diplomat-wasm.mjs";
|
|
98
|
+
import {FUNCTION_PARAM_ALLOC, internalConstructor} from "./diplomat-runtime.mjs";
|
|
99
|
+
|
|
100
|
+
FUNCTION_PARAM_ALLOC.reserve(internalConstructor, wasm, 63);
|
|
101
|
+
export * from './gpu.mjs';
|