@forsakringskassan/docs-generator 1.24.0

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 (36) hide show
  1. package/LICENSE.md +24 -0
  2. package/README.md +311 -0
  3. package/dist/compile-example.js +13406 -0
  4. package/dist/generator.d.ts +512 -0
  5. package/dist/generator.js +84168 -0
  6. package/dist/markdown.d.ts +243 -0
  7. package/dist/markdown.js +19369 -0
  8. package/dist/runtime.d.ts +1 -0
  9. package/dist/runtime.js +206572 -0
  10. package/dist/style/core.css +840 -0
  11. package/dist/style/index.css +927 -0
  12. package/dist/style/site.css +86 -0
  13. package/dist/tsdoc-metadata.json +11 -0
  14. package/package.json +68 -0
  15. package/templates/base.template.html +132 -0
  16. package/templates/component.template.html +28 -0
  17. package/templates/content-with-menu.template.html +15 -0
  18. package/templates/content-without-menu.template.html +10 -0
  19. package/templates/default.template.html +10 -0
  20. package/templates/example.template.html +70 -0
  21. package/templates/json.template.json +1 -0
  22. package/templates/macro/menu.html +39 -0
  23. package/templates/partials/footer.html +3 -0
  24. package/templates/partials/header.html +14 -0
  25. package/templates/partials/livereload.html +1 -0
  26. package/templates/partials/matomo.html +29 -0
  27. package/templates/partials/search-dialog.html +25 -0
  28. package/templates/partials/search-toolbar.html +9 -0
  29. package/templates/partials/selectable-version.html +28 -0
  30. package/templates/partials/spritesheet.html +44 -0
  31. package/templates/partials/theme-select.html +68 -0
  32. package/templates/partials/topnav.html +22 -0
  33. package/templates/partials/version-banner.html +14 -0
  34. package/templates/partials/version.html +3 -0
  35. package/templates/pattern.template.html +19 -0
  36. package/tsconfig-examples.json +9 -0
package/LICENSE.md ADDED
@@ -0,0 +1,24 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright © 2024 Försäkringskassan
4
+
5
+ Permission is hereby granted, free of charge, to any person
6
+ obtaining a copy of this software and associated documentation
7
+ files (the “Software”), to deal in the Software without
8
+ restriction, including without limitation the rights to use,
9
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the
11
+ Software is furnished to do so, subject to the following
12
+ conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,311 @@
1
+ # `@forsakringskassan/docs-generator`
2
+
3
+ ```bash
4
+ npm install --save-dev --save-exact @forsakringskassan/docs-generator
5
+ ```
6
+
7
+ ## Setup
8
+
9
+ ### Watch (development mode)
10
+
11
+ You can start a development server with watch for incremental builds using `.serve()`.
12
+
13
+ ```ts
14
+ const docs = new Generator({
15
+ /* ... */
16
+ processors: [livereloadProcessor({ enabled: true })],
17
+ /* ... */
18
+ });
19
+
20
+ docs.build([
21
+ /* ... */
22
+ ]);
23
+
24
+ docs.serve();
25
+ ```
26
+
27
+ ### Vendor alias
28
+
29
+ Vendor alias is optional, it lets you substitute one package for another when bundling. The example below substitutes the package `vue` with the package `vue/dist/esm.bundle.js`. When an alias is given the package can be imported using the given alias as well as the original package name. For instance, when using the following configuration "vue" can be imported and resolved as "vue/dist/esm.bundle.js".
30
+
31
+ ```ts
32
+ const docs = new Generator({
33
+ /* ... */
34
+ vendor: [
35
+ {
36
+ package: "vue",
37
+ expose: "named",
38
+ subpaths: [],
39
+ alias: "vue/dist/esm.bundle.js",
40
+ },
41
+ ],
42
+ /* ... */
43
+ });
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ### Using with Vue 2
49
+
50
+ Vue 2 requires an additional dependency to be installed:
51
+
52
+ ```bash
53
+ npm install --save-dev --save-exact @vue/component-compiler
54
+ ```
55
+
56
+ Create the `setup` callback in `docs/src/setup.ts`:
57
+
58
+ ```ts
59
+ import Vue from "vue";
60
+ import { type SetupOptions } from "@forsakringskassan/docs-generator";
61
+
62
+ /* optionally add global plugins or configuration */
63
+ //Vue.use(MyAwesomePlugin);
64
+
65
+ export function setup(options: SetupOptions): void {
66
+ const { rootComponent, selector } = options;
67
+ const vm = new Vue(rootComponent);
68
+ vm.$mount(selector);
69
+ }
70
+ ```
71
+
72
+ ### Using with Vue 3
73
+
74
+ Create the `setup` callback in `docs/src/setup.ts`:
75
+
76
+ ```ts
77
+ import { createApp } from "vue";
78
+ import { type SetupOptions } from "@forsakringskassan/docs-generator";
79
+
80
+ export function setup(options: SetupOptions): void {
81
+ const { rootComponent, selector } = options;
82
+ const app = createApp(rootComponent);
83
+
84
+ /* optionally add global plugins or configuration */
85
+ //app.use(MyAwesomePlugin);
86
+
87
+ app.mount(selector);
88
+ }
89
+ ```
90
+
91
+ ### Styling
92
+
93
+ Three CSS files are provided:
94
+
95
+ - `@forsakringskassan/docs-generator/style/index.css` (aliased as `@forsakringskassan/docs-generator/style`)
96
+ - `@forsakringskassan/docs-generator/style/core.css`
97
+ - `@forsakringskassan/docs-generator/style/site.css`
98
+
99
+ `core` contains the necessary styling for components and elements and `site` contains the layout, typography etc required for a documentation site to work.
100
+ `index` is a combination of the two and should be used in most cases.
101
+
102
+ Style can be compiled with `compileStyle(name, src, [options])`:
103
+
104
+ ```ts
105
+ const docs = new Generator({
106
+ /* ... */
107
+ });
108
+
109
+ docs.compileStyle("docs", "./docs/src/style.scss", {
110
+ appendTo: "head",
111
+ });
112
+ ```
113
+
114
+ Where `docs/src/style.scss` contains:
115
+
116
+ ```scss
117
+ @use "~@forsakringskassan/docs-generator/style";
118
+ ```
119
+
120
+ ### Markdown
121
+
122
+ #### Links `{@link ...}`
123
+
124
+ To create link to a different document use `{@link ID [TITLE]}`, e.g.:
125
+
126
+ ```md
127
+ See {@link MyAwesomeComponent} for details or the {@link getting-started getting started guide}.
128
+ ```
129
+
130
+ will be rendered as:
131
+
132
+ ```html
133
+ See
134
+ <a href="./components/my-awesome-component.html"
135
+ >MyAwesomeComponent<a>
136
+ for details or the
137
+ <a href="../guides/getting-started.html">getting started guide</a>.</a
138
+ ></a
139
+ >
140
+ ```
141
+
142
+ The ID can be either the document identifier, name or one of the aliases.
143
+ The link destination will always be relative to the current document.
144
+
145
+ #### Code fence
146
+
147
+ For configured languages (default `html` and `vue`) code fences are run as a live example in the browser with an option to display the source code.
148
+ The following tags can be used:
149
+
150
+ - `borderless` - removes the border from the example.
151
+ - `fullscreen` - enable support for viewing the example in fullscreen.
152
+ - `static` - force code to be rendered without live preview (only syntax highlight).
153
+ - `live-example` - mark example as containing the `LiveExample` component.
154
+ - `nomarkup` - for live examples this hides the syntax highlighted code and only displays the result of the running code.
155
+ - `test-id=STRING` - Sets the `data-test` attribute.
156
+
157
+ `static` and `live` are used to manually set whenever the code should be run as a live example or not.
158
+
159
+ ````md
160
+ ```html static
161
+ <p>This is displayed as syntax highlighted code only</p>
162
+ ```
163
+ ````
164
+
165
+ ````md
166
+ ```js live
167
+ alert("This is run in the browser");
168
+ ```
169
+ ````
170
+
171
+ Examples can be imported using the `import` directive:
172
+
173
+ ````md
174
+ ```import
175
+ MyAwesomeFile.vue
176
+ ```
177
+ ````
178
+
179
+ This will search for `MyAwesomeFile.vue` in the configured `exampleFolders`.
180
+ HTML-comments may be placed before or after the filename.
181
+
182
+ To import an example that uses the [LiveExample](https://github.com/Forsakringskassan/docs-live-example) component you also need to use the `live-example` tag.
183
+
184
+ ````md
185
+ ```import live-example
186
+ MyAwesomeLiveExampleFile.vue
187
+ ```
188
+ ````
189
+
190
+ #### Diagrams and flowcharts
191
+
192
+ You can generate diagrams from text by using [Mermaid](https://mermaidjs.github.io/).
193
+ The results are rendered as SVG in the browser.
194
+
195
+ ````md
196
+ ```mermaid
197
+ graph TD;
198
+ A-->B;
199
+ A-->C;
200
+ B-->D;
201
+ C-->D;
202
+ ```
203
+ ````
204
+
205
+ You can use the [Mermaid Live Editor](https://mermaid-js.github.io/mermaid-live-editor/) to help write your diagrams.
206
+
207
+ ### Frontmatter
208
+
209
+ #### `status`
210
+
211
+ Set a status badge for a component.
212
+
213
+ The following statuses are recognized:
214
+
215
+ - `Produktionsklar`
216
+ - `Deprekerad`
217
+ - `Experimentell`
218
+ - `Preliminär`
219
+ - `Draft` (deprecated alias for `Preliminär`)
220
+ - `Beta` (deprecated alias for `Preliminär`)
221
+
222
+ #### `title`
223
+
224
+ Document title used for `<title>` and `<nav>`
225
+
226
+ #### `visible`
227
+
228
+ Set to `false` to hide document from navigation menu.
229
+ Default `true`.
230
+
231
+ ### Inline tags
232
+
233
+ #### `{@link ...}`
234
+
235
+ Implicit title:
236
+
237
+ ```md
238
+ Use the {@link MyAwesomeComponent} component.
239
+ ```
240
+
241
+ Explicit title:
242
+
243
+ ```md
244
+ Use the {@link MyAwesomeComponent awesome component}.
245
+ ```
246
+
247
+ ### Templating
248
+
249
+ The [Nunjucks](https://mozilla.github.io/nunjucks/) templating engine is used for rendering documents to HTML.
250
+ See [templating documentation](https://mozilla.github.io/nunjucks/templating.html) for help.
251
+
252
+ These custom filters and tags are available:
253
+
254
+ #### `container`
255
+
256
+ ```
257
+ {% container "awesome-name" %}
258
+ ```
259
+
260
+ Creates a container which processors may inject content into.
261
+
262
+ ### Environment variables
263
+
264
+ #### `DOCS_ICON_LIB`
265
+
266
+ Preferred icon library package name.
267
+ Defaults to `@fkui/icon-lib-default`.
268
+ Makes it possible to dynamically load icons and get access to icon metadata.
269
+ The library must have been built using `@fkui/icon-lib-builder`.
270
+
271
+ ```js
272
+ const icons = await import(process.env.DOCS_ICON_LIB);
273
+
274
+ for (const entry of Object.values(icons)) {
275
+ entry.injectSpritesheet();
276
+ }
277
+ ```
278
+
279
+ ## Processors
280
+
281
+ ### Matomo
282
+
283
+ ```diff
284
+ const docs = new Generator({
285
+ processors: [
286
+ + matomoProcessor({
287
+ + siteId: "1",
288
+ + apiUrl: "https://matomo.example.net/",
289
+ + trackerUrl: "https://matomo.example.net/",
290
+ + }),
291
+ ],
292
+ });
293
+ ```
294
+
295
+ Optionally set `hostname` to limit which hostnames can run Matomo analytics:
296
+
297
+ ```diff
298
+ const docs = new Generator({
299
+ processors: [
300
+ matomoProcessor({
301
+ siteId: "1",
302
+ apiUrl: "https://matomo.example.net/",
303
+ trackerUrl: "https://matomo.example.net/",
304
+ + hostname: "docs.example.net",
305
+ }),
306
+ ],
307
+ });
308
+ ```
309
+
310
+ Only the domain must be specified, e.g it should not include `https://` or a path `/path/to/docs`.
311
+ Multiple hostnames can be specified as an array.