@humanonlyweb/writer 0.0.0-stage → 0.1.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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -2
  3. package/dist/components/WriterContent.d.ts +57 -0
  4. package/dist/components/WriterContent.js +114 -0
  5. package/dist/components/WriterEditor.js +232 -0
  6. package/dist/components/WriterEditor.vue.d.ts +70 -0
  7. package/dist/components/WriterToolbar.js +135 -0
  8. package/dist/components/WriterToolbar.vue.d.ts +27 -0
  9. package/dist/config.d.ts +39 -0
  10. package/dist/config.js +41 -0
  11. package/dist/docs/README.md +24 -0
  12. package/dist/docs/blocks.md +64 -0
  13. package/dist/docs/changelog.md +17 -0
  14. package/dist/docs/components/content.md +51 -0
  15. package/dist/docs/components/editor.md +236 -0
  16. package/dist/docs/components/toolbar.md +146 -0
  17. package/dist/docs/images.md +80 -0
  18. package/dist/docs/index.md +86 -0
  19. package/dist/docs/installation.md +74 -0
  20. package/dist/docs/limitations.md +11 -0
  21. package/dist/docs/localisation.md +35 -0
  22. package/dist/docs/parsing.md +47 -0
  23. package/dist/docs/security.md +16 -0
  24. package/dist/docs/storing.md +105 -0
  25. package/dist/docs/styling.md +47 -0
  26. package/dist/docs/word-count.md +16 -0
  27. package/dist/editor/commands.d.ts +1 -0
  28. package/dist/editor/commands.js +359 -0
  29. package/dist/editor/images.d.ts +1 -0
  30. package/dist/editor/images.js +400 -0
  31. package/dist/editor/live.d.ts +2 -0
  32. package/dist/editor/live.js +411 -0
  33. package/dist/editor/setup.d.ts +9 -0
  34. package/dist/editor/setup.js +485 -0
  35. package/dist/index.d.ts +11 -0
  36. package/dist/index.js +8 -0
  37. package/dist/load-parser.js +12 -0
  38. package/dist/nuxt/module.d.ts +35 -0
  39. package/dist/nuxt/module.js +114 -0
  40. package/dist/nuxt/runtime/plugin.d.ts +2 -0
  41. package/dist/nuxt/runtime/plugin.js +25 -0
  42. package/dist/nuxt/runtime/server/parse.d.ts +12 -0
  43. package/dist/nuxt/runtime/server/parse.js +15 -0
  44. package/dist/package.js +3 -0
  45. package/dist/parse.d.ts +16 -0
  46. package/dist/parse.js +62 -0
  47. package/dist/parser-options.d.ts +19 -0
  48. package/dist/placeholder.js +5 -0
  49. package/dist/render.d.ts +10 -0
  50. package/dist/render.js +97 -0
  51. package/dist/sanitize.d.ts +11 -0
  52. package/dist/sanitize.js +139 -0
  53. package/dist/stats.d.ts +8 -0
  54. package/dist/stats.js +17 -0
  55. package/dist/styles/core.css +275 -0
  56. package/dist/translations.d.ts +26 -0
  57. package/dist/translations.js +47 -0
  58. package/dist/types.d.ts +9 -0
  59. package/package.json +101 -4
@@ -0,0 +1,275 @@
1
+ /* @humanonlyweb/writer core styles: layout and Markdown source only, in a layer your CSS overrides. */
2
+ @layer humanonlyweb-writer {
3
+ [data-part="writer-editor"] {
4
+ display: grid;
5
+ }
6
+
7
+ /* The server-rendered textarea, until the editor loads. */
8
+ [data-part="writer-fallback"] {
9
+ box-sizing: border-box;
10
+ inline-size: 100%;
11
+ min-block-size: 10lh;
12
+ field-sizing: content;
13
+ padding: 0;
14
+ border: 0;
15
+ background: transparent;
16
+ color: inherit;
17
+ font: inherit;
18
+ resize: vertical;
19
+ }
20
+
21
+ [data-part="writer-fallback"]:focus-visible,
22
+ [data-part="writer-host"]:has(.cm-focused) {
23
+ outline: 2px solid Highlight;
24
+ outline-offset: 2px;
25
+ }
26
+
27
+ [data-part="writer-host"] .cm-content {
28
+ min-block-size: 10lh;
29
+ }
30
+
31
+ /* Markdown source: emphasis shows as itself, syntax marks recede. */
32
+ .cm-md-strong {
33
+ font-weight: bold;
34
+ }
35
+
36
+ .cm-md-em {
37
+ font-style: italic;
38
+ }
39
+
40
+ .cm-md-strike {
41
+ text-decoration: line-through;
42
+ }
43
+
44
+ /*
45
+ * Shared type scale: the editor's Markdown source and rendered content read the same
46
+ * tokens, so a heading is the same size in both. Defaults are the browser's own. Set
47
+ * them once, on any ancestor, to match your site:
48
+ * :root { --writer-h1: 2.5rem; --writer-code-font: "JetBrains Mono", monospace; }
49
+ */
50
+ .cm-md-code,
51
+ .cm-md-codeblock,
52
+ [data-part="writer-content"] :where(code, kbd, pre) {
53
+ font-family: var(--writer-code-font, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
54
+ font-size: var(--writer-code-size, 0.875em);
55
+ }
56
+
57
+ /* Code inside a code block is already sized by the block. */
58
+ .cm-md-codeblock .cm-md-code,
59
+ [data-part="writer-content"] :where(pre code) {
60
+ font-size: inherit;
61
+ }
62
+
63
+ .cm-md-link {
64
+ text-decoration: underline;
65
+ }
66
+
67
+ .cm-md-mark,
68
+ .cm-md-comment {
69
+ opacity: 0.6;
70
+ }
71
+
72
+ :where(.cm-md-h1, .cm-md-h2, .cm-md-h3, .cm-md-h4, .cm-md-h5, .cm-md-h6) {
73
+ font-weight: var(--writer-heading-weight, bold);
74
+ }
75
+
76
+ [data-part="writer-content"] :where(h1, h2, h3, h4, h5, h6) {
77
+ font-weight: var(--writer-heading-weight, bold);
78
+ }
79
+
80
+ :where(.cm-md-h1),
81
+ [data-part="writer-content"] :where(h1) {
82
+ font-size: var(--writer-h1, 2em);
83
+ }
84
+
85
+ :where(.cm-md-h2),
86
+ [data-part="writer-content"] :where(h2) {
87
+ font-size: var(--writer-h2, 1.5em);
88
+ }
89
+
90
+ :where(.cm-md-h3),
91
+ [data-part="writer-content"] :where(h3) {
92
+ font-size: var(--writer-h3, 1.17em);
93
+ }
94
+
95
+ :where(.cm-md-h4),
96
+ [data-part="writer-content"] :where(h4) {
97
+ font-size: var(--writer-h4, 1em);
98
+ }
99
+
100
+ :where(.cm-md-h5),
101
+ [data-part="writer-content"] :where(h5) {
102
+ font-size: var(--writer-h5, 0.83em);
103
+ }
104
+
105
+ :where(.cm-md-h6),
106
+ [data-part="writer-content"] :where(h6) {
107
+ font-size: var(--writer-h6, 0.67em);
108
+ }
109
+
110
+ /* Images never overflow their column. */
111
+ [data-part="writer-content"] :where(img) {
112
+ max-inline-size: 100%;
113
+ block-size: auto;
114
+ }
115
+
116
+ /* Live preview: rendered blocks and images, and formatting standing in for syntax. */
117
+ .cm-md-preview {
118
+ display: flow-root;
119
+ white-space: normal;
120
+ cursor: text;
121
+ border-radius: 4px;
122
+ }
123
+
124
+ .cm-md-preview:hover {
125
+ outline: 1px dashed color-mix(in srgb, currentColor 30%, transparent);
126
+ outline-offset: 4px;
127
+ }
128
+
129
+ [data-part="writer-content"] :where(blockquote) {
130
+ margin-inline: 0;
131
+ padding-inline-start: var(--writer-quote-indent, 1em);
132
+ border-inline-start: var(--writer-quote-border-width, 3px) solid
133
+ var(--writer-quote-border-color, color-mix(in srgb, currentColor 25%, transparent));
134
+ }
135
+
136
+ .cm-md-hr {
137
+ background: linear-gradient(color-mix(in srgb, currentColor 25%, transparent) 0 0) center / 100%
138
+ 1px no-repeat;
139
+ }
140
+
141
+ /* A block open for editing: framed (--writer-block-inset, --writer-block-background), its fence lines small. */
142
+ .cm-md-block-fence {
143
+ font-family: var(--writer-code-font, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
144
+ font-size: 0.75em;
145
+ opacity: 0.55;
146
+ }
147
+
148
+ /* Image cards: the published figure, with its caption and alt text editable. */
149
+ .cm-md-image {
150
+ display: flow-root;
151
+ white-space: normal;
152
+ }
153
+
154
+ .cm-md-image-frame {
155
+ position: relative;
156
+ display: grid;
157
+ border-radius: 4px;
158
+ }
159
+
160
+ .cm-md-image-frame img {
161
+ display: block;
162
+ inline-size: 100%;
163
+ block-size: auto;
164
+ }
165
+
166
+ .cm-md-image-frame[data-empty] {
167
+ aspect-ratio: 16 / 9;
168
+ place-items: center;
169
+ border: 1px dashed color-mix(in srgb, currentColor 35%, transparent);
170
+ }
171
+
172
+ .cm-md-image-frame[data-dropping] {
173
+ outline: 2px dashed Highlight;
174
+ outline-offset: -2px;
175
+ }
176
+
177
+ /* display: block above would otherwise beat the hidden attribute and take a grid row. */
178
+ .cm-md-image-frame img[hidden],
179
+ .cm-md-image-frame:not([data-empty]) .cm-md-image-empty,
180
+ .cm-md-image-frame:not([data-uploading]) .cm-md-image-status,
181
+ .cm-md-image-frame[data-empty] .cm-md-image-actions {
182
+ display: none;
183
+ }
184
+
185
+ .cm-md-image-empty {
186
+ display: flex;
187
+ flex-wrap: wrap;
188
+ gap: 0.5em;
189
+ align-items: baseline;
190
+ justify-content: center;
191
+ padding: 1em;
192
+ font-size: 0.85em;
193
+ }
194
+
195
+ .cm-md-image-status,
196
+ .cm-md-image-actions {
197
+ position: absolute;
198
+ inset-block-start: 0.5rem;
199
+ display: flex;
200
+ gap: 0.25rem;
201
+ font-size: 0.8rem;
202
+ }
203
+
204
+ .cm-md-image-status {
205
+ inset-inline-start: 0.5rem;
206
+ padding: 0.15em 0.5em;
207
+ border-radius: 3px;
208
+ background: rgb(0 0 0 / 0.6);
209
+ color: #fff;
210
+ }
211
+
212
+ .cm-md-image-actions {
213
+ inset-inline-end: 0.5rem;
214
+ opacity: 0;
215
+ transition: opacity 0.15s;
216
+ }
217
+
218
+ .cm-md-image:is(:hover, :focus-within, [data-selected]) .cm-md-image-actions {
219
+ opacity: 1;
220
+ }
221
+
222
+ .cm-md-image[data-selected] .cm-md-image-frame {
223
+ outline: 2px solid Highlight;
224
+ outline-offset: 2px;
225
+ }
226
+
227
+ /* Caption and alt fields read as text, not form fields. */
228
+ .cm-md-image :is(.cm-md-image-caption, .cm-md-image-alt input) {
229
+ box-sizing: border-box;
230
+ inline-size: 100%;
231
+ padding: 0;
232
+ border: 0;
233
+ background: transparent;
234
+ color: inherit;
235
+ font: inherit;
236
+ }
237
+
238
+ .cm-md-image-caption:focus,
239
+ .cm-md-image-alt input:focus {
240
+ outline: none;
241
+ }
242
+
243
+ .cm-md-image-alt {
244
+ display: flex;
245
+ gap: 0.5em;
246
+ align-items: baseline;
247
+ margin-block-start: 0.25em;
248
+ font-size: 0.8em;
249
+ opacity: 0.75;
250
+ }
251
+
252
+ .cm-md-image-alt:focus-within {
253
+ opacity: 1;
254
+ }
255
+
256
+ .cm-md-image-alt span {
257
+ flex: none;
258
+ font-weight: 600;
259
+ }
260
+
261
+ .cm-md-task {
262
+ margin: 0 0.4em 0 0;
263
+ vertical-align: middle;
264
+ }
265
+
266
+ [data-part="writer-toolbar"] {
267
+ display: flex;
268
+ flex-wrap: wrap;
269
+ gap: 4px;
270
+ }
271
+
272
+ [data-part="writer-toolbar-item"][aria-disabled="true"] {
273
+ opacity: 0.5;
274
+ }
275
+ }
@@ -0,0 +1,26 @@
1
+ export type CommandName = "bold" | "italic" | "strikethrough" | "code" | "link" | "heading1" | "heading2" | "heading3" | "quote" | "bulletList" | "orderedList" | "taskList" | "codeBlock" | "table" | "divider" | "image" | "footnote" | "undo" | "redo";
2
+ /** Every string the components render or announce. Override any with `createWriter({ translations })`. */
3
+ export interface WriterTranslations {
4
+ /** The editor's accessible name, when `label` isn't set. */
5
+ editor: string;
6
+ /** The toolbar's accessible name, when `label` isn't set. */
7
+ toolbar: string;
8
+ /** Toolbar buttons and slash menu entries. */
9
+ commands: Record<CommandName, string>;
10
+ /** A task checkbox's name in live preview, when the task has no text yet. */
11
+ task: string;
12
+ /** The image card in live preview. */
13
+ imageAlt: string;
14
+ imageAltHint: string;
15
+ imageCaption: string;
16
+ imageDrop: string;
17
+ imageChoose: string;
18
+ imageUrl: string;
19
+ imageReplace: string;
20
+ imageRemove: string;
21
+ imageUploading: string;
22
+ }
23
+ export type WriterTranslationsInput = Partial<Omit<WriterTranslations, "commands">> & {
24
+ commands?: Partial<WriterTranslations["commands"]>;
25
+ };
26
+ export declare const defaultTranslations: WriterTranslations;
@@ -0,0 +1,47 @@
1
+ // src/translations.ts
2
+ const defaultTranslations = {
3
+ editor: "Markdown editor",
4
+ toolbar: "Formatting",
5
+ commands: {
6
+ bold: "Bold",
7
+ italic: "Italic",
8
+ strikethrough: "Strikethrough",
9
+ code: "Code",
10
+ link: "Link",
11
+ heading1: "Heading 1",
12
+ heading2: "Heading 2",
13
+ heading3: "Heading 3",
14
+ quote: "Quote",
15
+ bulletList: "Bulleted list",
16
+ orderedList: "Numbered list",
17
+ taskList: "Task list",
18
+ codeBlock: "Code block",
19
+ table: "Table",
20
+ divider: "Divider",
21
+ image: "Image",
22
+ footnote: "Footnote",
23
+ undo: "Undo",
24
+ redo: "Redo"
25
+ },
26
+ task: "Task",
27
+ imageAlt: "Alt text",
28
+ imageAltHint: "Describe the image for people who can't see it",
29
+ imageCaption: "Add a caption",
30
+ imageDrop: "Drop an image here, or",
31
+ imageChoose: "Choose an image",
32
+ imageUrl: "Image URL",
33
+ imageReplace: "Replace",
34
+ imageRemove: "Remove",
35
+ imageUploading: "Uploading…"
36
+ };
37
+ function resolveTranslations(input = {}) {
38
+ return {
39
+ ...defaultTranslations,
40
+ ...input,
41
+ commands: {
42
+ ...defaultTranslations.commands,
43
+ ...input.commands
44
+ }
45
+ };
46
+ }
47
+ export { defaultTranslations, resolveTranslations };
@@ -0,0 +1,9 @@
1
+ import { CommandName } from "./translations.js";
2
+ /** What `<WriterToolbar>` needs from `<WriterEditor>`: pass the editor's template ref. */
3
+ export interface ToolbarEditor {
4
+ ready: boolean;
5
+ active: ReadonlySet<CommandName>;
6
+ canUndo?: boolean;
7
+ canRedo?: boolean;
8
+ run(command: CommandName): boolean;
9
+ }
package/package.json CHANGED
@@ -1,6 +1,103 @@
1
1
  {
2
2
  "name": "@humanonlyweb/writer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Markdown block editor and renderer for Vue and Nuxt: CodeMirror editing, Comark rendering, SSR-safe.",
5
+ "keywords": [
6
+ "a11y",
7
+ "codemirror",
8
+ "comark",
9
+ "editor",
10
+ "markdown",
11
+ "nuxt",
12
+ "ssr",
13
+ "vue"
14
+ ],
15
+ "homepage": "https://github.com/humanonlyweb/writer#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/humanonlyweb/writer/issues"
18
+ },
19
+ "license": "MIT",
20
+ "author": "HumanOnlyWeb",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/humanonlyweb/writer.git"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "type": "module",
29
+ "sideEffects": [
30
+ "**/*.css"
31
+ ],
32
+ "exports": {
33
+ ".": "./dist/index.js",
34
+ "./parse": "./dist/parse.js",
35
+ "./package.json": "./package.json",
36
+ "./nuxt": "./dist/nuxt/module.js",
37
+ "./core.css": "./dist/styles/core.css"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "build": "vp pack && nuxt build docs && node scripts/package-docs.mjs",
44
+ "dev": "vp pack --watch",
45
+ "test": "vp test",
46
+ "check": "nuxt prepare docs && vp check",
47
+ "typecheck": "vue-tsc --noEmit",
48
+ "docs": "nuxt dev docs",
49
+ "docs:build": "nuxt build docs",
50
+ "docs:preview": "nuxt build docs && wrangler dev --config docs/wrangler.jsonc",
51
+ "docs:deploy": "nuxt build docs && wrangler deploy --config docs/wrangler.jsonc",
52
+ "docs:typecheck": "nuxt typecheck docs",
53
+ "prepublishOnly": "vp run build",
54
+ "prepare": "vp config --no-agent"
55
+ },
56
+ "dependencies": {
57
+ "@codemirror/autocomplete": "^6.20.4",
58
+ "@codemirror/commands": "^6.11.1",
59
+ "@codemirror/lang-markdown": "^6.5.2",
60
+ "@codemirror/language": "^6.13.1",
61
+ "@codemirror/state": "^6.7.6",
62
+ "@codemirror/view": "^6.43.15",
63
+ "@lezer/highlight": "^1.2.5",
64
+ "@lezer/markdown": "^1.8.1",
65
+ "comark": "^0.8.1",
66
+ "rangi": "^2.2.0"
67
+ },
68
+ "devDependencies": {
69
+ "@humanonlyweb/ui": "^0.1.0",
70
+ "@nuxt/fonts": "1.0.1",
71
+ "@nuxt/kit": "^4.6.2",
72
+ "@nuxt/schema": "^4.6.2",
73
+ "@types/node": "26.6.5",
74
+ "@vitejs/plugin-vue": "6.0.10",
75
+ "@vitest/browser-playwright": "5.0.5",
76
+ "@vue/test-utils": "2.5.1",
77
+ "axe-core": "4.14.0",
78
+ "nuxt": "^4.6.2",
79
+ "playwright": "1.64.1",
80
+ "typescript": "npm:typescript-native-bridge@6.0.3-bridge.19.tsgo.7.0.2",
81
+ "unplugin-vue": "8.0.0",
82
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
83
+ "vite-plus": "1.4.0",
84
+ "vue": "3.5.44",
85
+ "vue-router": "5.4.0",
86
+ "vue-tsc": "3.3.13",
87
+ "wrangler": "4.151.1"
88
+ },
89
+ "peerDependencies": {
90
+ "@nuxt/kit": "^4.0.0",
91
+ "vue": "^3.5.0"
92
+ },
93
+ "peerDependenciesMeta": {
94
+ "@nuxt/kit": {
95
+ "optional": true
96
+ }
97
+ },
98
+ "overrides": {
99
+ "typescript": "$typescript",
100
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0"
101
+ },
102
+ "packageManager": "bun@1.4.4"
103
+ }