koffi 2.9.0 → 2.9.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 (89) hide show
  1. package/CHANGELOG.md +57 -46
  2. package/build/koffi/darwin_arm64/koffi.node +0 -0
  3. package/build/koffi/darwin_x64/koffi.node +0 -0
  4. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  5. package/build/koffi/{freebsd_i386 → freebsd_ia32}/koffi.node +0 -0
  6. package/build/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm32/koffi.node +0 -0
  8. package/build/koffi/linux_arm64/koffi.node +0 -0
  9. package/build/koffi/{linux_i386 → linux_ia32}/koffi.node +0 -0
  10. package/build/koffi/linux_riscv64/koffi.node +0 -0
  11. package/build/koffi/linux_x64/koffi.node +0 -0
  12. package/build/koffi/musl_x64/koffi.node +0 -0
  13. package/build/koffi/{openbsd_i386 → openbsd_ia32}/koffi.node +0 -0
  14. package/build/koffi/openbsd_x64/koffi.node +0 -0
  15. package/build/koffi/win32_arm64/koffi.node +0 -0
  16. package/build/koffi/{win32_i386 → win32_ia32}/koffi.node +0 -0
  17. package/build/koffi/win32_x64/koffi.node +0 -0
  18. package/doc/README.md +27 -0
  19. package/doc/assets.ini +19 -0
  20. package/doc/develop.sh +14 -0
  21. package/doc/flaat/flaat.css +25 -0
  22. package/doc/flaat/flaat.js +150 -0
  23. package/doc/flaat/normal.css +320 -0
  24. package/doc/flaat/print.css +30 -0
  25. package/doc/flaat/small.css +94 -0
  26. package/doc/{benchmarks.md → pages/benchmarks.md} +14 -18
  27. package/doc/{callbacks.md → pages/callbacks.md} +27 -36
  28. package/doc/{contribute.md → pages/contribute.md} +10 -12
  29. package/doc/{functions.md → pages/functions.md} +29 -34
  30. package/doc/pages/index.md +20 -0
  31. package/doc/{input.md → pages/input.md} +28 -33
  32. package/doc/{migration.md → pages/migration.md} +7 -10
  33. package/doc/{misc.md → pages/misc.md} +19 -23
  34. package/doc/{output.md → pages/output.md} +17 -20
  35. package/doc/{packaging.md → pages/packaging.md} +8 -10
  36. package/doc/{platforms.md → pages/platforms.md} +2 -4
  37. package/doc/{pointers.md → pages/pointers.md} +13 -16
  38. package/doc/{start.md → pages/start.md} +12 -14
  39. package/doc/{unions.md → pages/unions.md} +5 -7
  40. package/doc/{variables.md → pages/variables.md} +7 -11
  41. package/doc/pages.ini +88 -0
  42. package/doc/static/koffi.css +21 -0
  43. package/doc/static/koffi.js +21 -0
  44. package/doc/static/koffi.png +0 -0
  45. package/doc/static/print.css +22 -0
  46. package/doc/templates/page.html +40 -0
  47. package/index.d.ts +2 -1
  48. package/index.js +2 -2
  49. package/indirect.js +2 -2
  50. package/package.json +2 -2
  51. package/src/koffi/src/call.cc +2 -0
  52. package/doc/Makefile +0 -20
  53. package/doc/benchmarks.xlsx +0 -0
  54. package/doc/changelog.md +0 -5
  55. package/doc/conf.py +0 -118
  56. package/doc/index.rst +0 -47
  57. package/doc/make.bat +0 -35
  58. package/doc/poetry.lock +0 -521
  59. package/doc/pyproject.toml +0 -19
  60. package/doc/static/bench_linux.png +0 -0
  61. package/doc/static/bench_windows.png +0 -0
  62. package/doc/static/custom.css +0 -70
  63. package/doc/static/node_c.webp +0 -0
  64. package/doc/static/opensans/LICENSE.txt +0 -202
  65. package/doc/static/opensans/OpenSans.css +0 -39
  66. package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff +0 -0
  67. package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff2 +0 -0
  68. package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff +0 -0
  69. package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff2 +0 -0
  70. package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff +0 -0
  71. package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff2 +0 -0
  72. package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff +0 -0
  73. package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff2 +0 -0
  74. package/doc/static/perf_linux_20220623.png +0 -0
  75. package/doc/static/perf_linux_20220623_2.png +0 -0
  76. package/doc/static/perf_linux_20220627.png +0 -0
  77. package/doc/static/perf_linux_20220628.png +0 -0
  78. package/doc/static/perf_linux_20220812.png +0 -0
  79. package/doc/static/perf_windows_20220623.png +0 -0
  80. package/doc/static/perf_windows_20220623_2.png +0 -0
  81. package/doc/static/perf_windows_20220627.png +0 -0
  82. package/doc/static/perf_windows_20220628.png +0 -0
  83. package/doc/static/perf_windows_20220812.png +0 -0
  84. package/doc/templates/badges.html +0 -7
  85. package/doc/templates/logo.html +0 -3
  86. /package/build/koffi/{win32_i386 → win32_ia32}/koffi.exp +0 -0
  87. /package/build/koffi/{win32_i386 → win32_ia32}/koffi.lib +0 -0
  88. /package/doc/static/{perf_linux_20231028.png → perf_linux.png} +0 -0
  89. /package/doc/static/{perf_windows_20231028.png → perf_windows.png} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,9 +1,23 @@
1
- # Changelog
1
+ # Version history
2
2
 
3
- ## Version history
3
+ > [!NOTE]
4
+ > Consult the [migration guide](migration) to migrate between major Koffi versions.
5
+
6
+ ## Koffi 2
4
7
 
5
8
  ### Koffi 2.9
6
9
 
10
+ #### Koffi 2.9.2 (2024-11-08)
11
+
12
+ - Fix non-aligned pointers when pushing UTF-16 and UTF-32 string parameters
13
+ - Various documentation fixes and improvements
14
+
15
+ #### Koffi 2.9.1 (2024-09-23)
16
+
17
+ - Fix x86 32-bit support regression in 2.9.0
18
+ - Add missing TS definition for `koffi.alloc()`
19
+ - Support `koffi.load(null)` in TS definition file
20
+
7
21
  #### Koffi 2.9.0 (2024-07-22)
8
22
 
9
23
  - Add support for char32_t and wchar_t (wide) strings
@@ -15,9 +29,8 @@
15
29
 
16
30
  - Work around MSVC compiler bug introduced in Visual Studio 17.10
17
31
 
18
- ```{warning}
32
+ > [!WARNING]
19
33
  Use on platforms without pre-built binaries is broken in Koffi 2.8.10, skip this version.
20
- ```
21
34
 
22
35
  #### Koffi 2.8.9 (2024-05-17)
23
36
 
@@ -33,7 +46,7 @@ Use on platforms without pre-built binaries is broken in Koffi 2.8.10, skip this
33
46
 
34
47
  #### Koffi 2.8.6 (2024-04-12)
35
48
 
36
- - Support [loading library](functions.md#loading-options) with RTLD_DEEPBIND where supported
49
+ - Support [loading library](functions#loading-options) with RTLD_DEEPBIND where supported
37
50
 
38
51
  #### Koffi 2.8.5 (2024-04-11)
39
52
 
@@ -45,13 +58,12 @@ Use on platforms without pre-built binaries is broken in Koffi 2.8.10, skip this
45
58
 
46
59
  - Use simpler workaround for Node 20.12+ and 21.6+ to avoid excessive memory use
47
60
 
48
- ```{warning}
49
- Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
50
- ```
61
+ > [!WARNING]
62
+ > Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
51
63
 
52
64
  #### Koffi 2.8.2 (2024-04-07)
53
65
 
54
- - Support [loading library](functions.md#loading-options) with RTLD_GLOBAL on POSIX platforms
66
+ - Support [loading library](functions#loading-options) with RTLD_GLOBAL on POSIX platforms
55
67
 
56
68
  #### Koffi 2.8.1 (2024-04-04)
57
69
 
@@ -60,7 +72,7 @@ Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
60
72
  #### Koffi 2.8.0 (2024-02-12)
61
73
 
62
74
  - Support pushing pointers for string arguments
63
- - Add `koffi.alloc()` for [stable pointers](output.md#stable-pointers)
75
+ - Add `koffi.alloc()` for [stable pointers](output#stable-pointers)
64
76
 
65
77
  ### Koffi 2.7
66
78
 
@@ -83,13 +95,13 @@ Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
83
95
 
84
96
  #### Koffi 2.7.1 (2024-01-02)
85
97
 
86
- - Support C-like `int[3]` syntax for [fixed array types](input.md#fixed-size-c-arrays)
98
+ - Support C-like `int[3]` syntax for [fixed array types](input#fixed-size-c-arrays)
87
99
  - Refuse type specifiers with invalid tokens at the end (previously ignored)
88
100
 
89
101
  #### Koffi 2.7.0 (2023-12-21)
90
102
 
91
- - Support alternative [callback calling convention](callbacks.md#callback-types) in classic syntax
92
- - Change syntax for [calling conventions](functions.md#calling-conventions) with classic syntax
103
+ - Support alternative [callback calling convention](callbacks#callback-types) in classic syntax
104
+ - Change syntax for [calling conventions](functions#calling-conventions) with classic syntax
93
105
  - Drop unused "internal" property from Koffi
94
106
 
95
107
  ### Koffi 2.6
@@ -101,7 +113,7 @@ Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
101
113
  #### Koffi 2.6.11 (2023-12-05)
102
114
 
103
115
  - Speed up resolving simple and often used type names
104
- - Fix use of optional length argument with [koffi.encode()](variables.md#encode-to-c-memory)
116
+ - Fix use of optional length argument with [koffi.encode()](variables#encode-to-c-memory)
105
117
 
106
118
  #### Koffi 2.6.10 (2023-11-29)
107
119
 
@@ -114,9 +126,8 @@ Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
114
126
  - Show detected version of Node when not adequate
115
127
  - Minor documentation fixes
116
128
 
117
- ```{warning}
118
- Loading Win32 system libraries can fail in Koffi 2.6.8, skip this version.
119
- ```
129
+ > [!WARNING]
130
+ > Loading Win32 system libraries can fail in Koffi 2.6.8, skip this version.
120
131
 
121
132
  #### Koffi 2.6.6 (2023-10-28)
122
133
 
@@ -135,9 +146,8 @@ Loading Win32 system libraries can fail in Koffi 2.6.8, skip this version.
135
146
 
136
147
  - Add indirect loading script to help some bundlers
137
148
 
138
- ```{warning}
139
- Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
140
- ```
149
+ > [!WARNING]
150
+ > Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
141
151
 
142
152
  #### Koffi 2.6.1 (2023-09-18)
143
153
 
@@ -148,9 +158,9 @@ Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
148
158
 
149
159
  **New features:**
150
160
 
151
- - Use [koffi.symbol()](variables.md#variable-definitions) to make pointers to exported variables (or other symbols)
152
- - Use [koffi.encode()](variables.md#encode-to-c-memory) to explictly encode data from JS to C memory
153
- - Use shared library [lazy-loading](functions.md#loading-options) (RTLD_LAZY) on POSIX platforms
161
+ - Use [koffi.symbol()](variables#variable-definitions) to make pointers to exported variables (or other symbols)
162
+ - Use [koffi.encode()](variables#encode-to-c-memory) to explictly encode data from JS to C memory
163
+ - Use shared library [lazy-loading](functions#loading-options) (RTLD_LAZY) on POSIX platforms
154
164
 
155
165
  **Other changes:**
156
166
 
@@ -167,7 +177,7 @@ Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
167
177
  #### Koffi 2.5.19 (2023-08-29)
168
178
 
169
179
  - Create thread-safe function broker lazily
170
- - Add [koffi.reset()](misc.md#reset-internal-state) for type names and async broker
180
+ - Add [koffi.reset()](misc#reset-internal-state) for type names and async broker
171
181
 
172
182
  #### Koffi 2.5.18 (2023-08-27)
173
183
 
@@ -179,9 +189,8 @@ Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
179
189
  - Fix DLL error when using Koffi from NW.js on Windows
180
190
  - Simplify NW.js Koffi example
181
191
 
182
- ```{warning}
183
- Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those versions.
184
- ```
192
+ > [!WARNING]
193
+ > Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those versions.
185
194
 
186
195
  #### Koffi 2.5.12 (2023-08-21)
187
196
 
@@ -190,7 +199,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
190
199
 
191
200
  #### Koffi 2.5.11 (2023-08-03)
192
201
 
193
- - Support casting function pointers with [koffi.as()](pointers.md#handling-void-pointers)
202
+ - Support casting function pointers with [koffi.as()](pointers#handling-void-pointers)
194
203
  - Build in C++20 mode
195
204
 
196
205
  #### Koffi 2.5.10 (2023-08-01)
@@ -212,7 +221,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
212
221
  #### Koffi 2.5.8 (2023-07-26)
213
222
 
214
223
  - Add more search paths for native Koffi modules
215
- - Add section [about bundling](start.md#bundling-koffi) to documentation
224
+ - Add section [about bundling](start#bundling-koffi) to documentation
216
225
 
217
226
  #### Koffi 2.5.7 (2023-07-19)
218
227
 
@@ -249,7 +258,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
249
258
 
250
259
  **New features:**
251
260
 
252
- - Support [union types](unions.md)
261
+ - Support [union types](unions)
253
262
 
254
263
  **Other fixes:**
255
264
 
@@ -267,8 +276,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
267
276
 
268
277
  **Main changes:**
269
278
 
270
- - Support [decoding function pointers](functions.md#decode-pointer-to-function) to callable functions
271
- - Support calling function pointers with [koffi.call()](functions.md#call-pointer-directly)
279
+ - Support [decoding function pointers](functions#decode-pointer-to-function) to callable functions
280
+ - Support calling function pointers with [koffi.call()](functions#call-pointer-directly)
272
281
  - Deprecate `koffi.callback` in favor of `koffi.proto`
273
282
 
274
283
  **Other changes:**
@@ -378,9 +387,9 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
378
387
 
379
388
  **Main changes:**
380
389
 
381
- - Fix type parser issues (such as ignoring some [disposable qualifiers](pointers.md#disposable-types))
390
+ - Fix type parser issues (such as ignoring some [disposable qualifiers](pointers#disposable-types))
382
391
  - Fix crash when using disposable types in output parameters
383
- - Add basic [koffi.stats()](misc.md#usage-statistics) interface
392
+ - Add basic [koffi.stats()](misc#usage-statistics) interface
384
393
 
385
394
  **Other changes:**
386
395
 
@@ -398,8 +407,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
398
407
  **Main changes:**
399
408
 
400
409
  - Allow buffers (TypedArray or ArrayBuffer) values for input and/or output pointer arguments (for polymorphic arguments)
401
- - Support opaque buffers (TypedArray or ArrayBuffer) values in `koffi.decode()` to [decode output buffers](output.md#output-buffers)
402
- - Decode non-string types as arrays when an [explicit length is passed to koffi.decode()](callbacks.md#decoding-pointer-arguments)
410
+ - Support opaque buffers (TypedArray or ArrayBuffer) values in `koffi.decode()` to [decode output buffers](output#output-buffers)
411
+ - Decode non-string types as arrays when an [explicit length is passed to koffi.decode()](callbacks#decoding-pointer-arguments)
403
412
 
404
413
  **Other changes:**
405
414
 
@@ -430,7 +439,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
430
439
 
431
440
  **Main fixes:**
432
441
 
433
- - Support transparent [asynchronous callbacks](callbacks.md#asynchronous-callbacks)
442
+ - Support transparent [asynchronous callbacks](callbacks#asynchronous-callbacks)
434
443
  - Expand from a maximum of 16+16 to 1024 callbacks running in parallel
435
444
 
436
445
  **Other fixes:**
@@ -448,8 +457,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
448
457
 
449
458
  **New features:**
450
459
 
451
- - Add [koffi.decode()](callbacks.md#decoding-pointer-arguments) for callback pointer arguments
452
- - Support transparent [output string parameters](output.md#string-buffer-example)
460
+ - Add [koffi.decode()](callbacks#decoding-pointer-arguments) for callback pointer arguments
461
+ - Support transparent [output string parameters](output#string-buffer-example)
453
462
  - Add `koffi.offsetof()` utility function
454
463
  - Support optional *this* binding in `koffi.register()`
455
464
 
@@ -462,7 +471,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
462
471
 
463
472
  #### Koffi 2.1.5 (2022-11-27)
464
473
 
465
- - Add missing README.md file to NPM package
474
+ - Add missing README file to NPM package
466
475
 
467
476
  #### Koffi 2.1.4 (2022-11-25)
468
477
 
@@ -491,8 +500,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
491
500
 
492
501
  **Main changes:**
493
502
 
494
- - Add [koffi.as()](pointers.md#handling-void-pointers) to support polymorphic APIs based on `void *` parameters
495
- - Add [endian-sensitive integer types](input.md#endian-sensitive-integers): `intX_le_t`, `intX_be_t`, `uintX_le_t`, `uintX_be_t`
503
+ - Add [koffi.as()](pointers#handling-void-pointers) to support polymorphic APIs based on `void *` parameters
504
+ - Add [endian-sensitive integer types](input#endian-sensitive-integers): `intX_le_t`, `intX_be_t`, `uintX_le_t`, `uintX_be_t`
496
505
  - Accept typed arrays for `void *` parameters
497
506
  - Introduce `koffi.opaque()` to replace `koffi.handle()` (which remains supported until Koffi 3.0)
498
507
  - Support JS Array and TypedArray to fill struct and array pointer members
@@ -515,8 +524,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
515
524
 
516
525
  **Major new features:**
517
526
 
518
- - Add [disposable types](pointers.md#disposable-types) for automatic disposal of C values (such as heap-allocated strings)
519
- - Add support for [registered callbacks](callbacks.md#registered-callbacks), that can be called after the initial FFI call
527
+ - Add [disposable types](pointers#disposable-types) for automatic disposal of C values (such as heap-allocated strings)
528
+ - Add support for [registered callbacks](callbacks#registered-callbacks), that can be called after the initial FFI call
520
529
  - Support named pointer types
521
530
  - Support complex type specifications outside of prototype parser
522
531
 
@@ -533,7 +542,9 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
533
542
  - Change handling of opaque handles, which must be used through pointers
534
543
  - Support all types in `koffi.introspect(type)`
535
544
 
536
- Consult the [migration guide](migration.md) for more information.
545
+ Consult the [migration guide](migration) for more information.
546
+
547
+ ## Koffi 1
537
548
 
538
549
  ### Koffi 1.3
539
550
 
@@ -685,7 +696,7 @@ This entry documents changes since version 1.1.0.
685
696
  - Make sure we have a redzone below the stack for all architectures
686
697
  - Use slower allocation for big objects instead of failing
687
698
 
688
- ## Todo list
699
+ # Todo list
689
700
 
690
701
  The following features and improvements are planned, not necessarily in that order:
691
702
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/doc/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Install required dependencies
2
+
3
+ On Debian and Ubuntu use the following commands:
4
+
5
+ ```sh
6
+ sudo apt update
7
+ sudo apt install build-essential
8
+ ```
9
+
10
+ On RPM-based distributions such as Fedora or Rocky Linux, use:
11
+
12
+ ```sh
13
+ sudo dnf groupinstall "Development Tools"
14
+ sudo dnf install clang
15
+ ```
16
+
17
+ # Run the develop script
18
+
19
+ Run the development script from the website directory:
20
+
21
+ ```sh
22
+ ./develop.sh
23
+ ```
24
+
25
+ Open the proposed link at `http://localhost:8000/`.
26
+
27
+ Change page content at will and builds will happen automatically. You just need to refresh the page.
package/doc/assets.ini ADDED
@@ -0,0 +1,19 @@
1
+ EsbuildPath = ../../vendor/esbuild/bin
2
+
3
+ [favicon.png]
4
+ Type = Copy
5
+ From = static/koffi.png
6
+
7
+ [static]
8
+ Type = Copy
9
+ From = static
10
+ Ignore = favicon.png *.js *.css
11
+
12
+ [static/site.min.js]
13
+ Type = Bundle
14
+ Source = static/koffi.js
15
+
16
+ [static/site.min.css]
17
+ Type = Bundle
18
+ Source = static/koffi.css
19
+ Options = --loader:.woff=file --loader:.woff2=file --loader:.png=file --loader:.webp=file
package/doc/develop.sh ADDED
@@ -0,0 +1,14 @@
1
+ #!/bin/bash -e
2
+
3
+ cd "$(dirname $0)"
4
+
5
+ ../../bootstrap.sh
6
+ ../../felix -pFast serf hodler
7
+
8
+ trap 'kill $(jobs -p) 2>/dev/null' EXIT
9
+ trap 'kill $(jobs -p) 2>/dev/null' SIGINT
10
+
11
+ ../../bin/Fast/serf dist/ &
12
+ ../../bin/Fast/hodler . -O dist --loop &
13
+
14
+ wait $(jobs -p)
@@ -0,0 +1,25 @@
1
+ /* Copyright (C) 2024 Niels Martignène <niels.martignene@protonmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the “Software”), to deal in
5
+ the Software without restriction, including without limitation the rights to use,
6
+ copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
+ Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
+ OTHER DEALINGS IN THE SOFTWARE. */
21
+
22
+ @import url('../../../vendor/opensans/OpenSans.css');
23
+ @import url('./normal.css');
24
+ @import url('./small.css');
25
+ @import url('./print.css');
@@ -0,0 +1,150 @@
1
+ // Copyright (C) 2024 Niels Martignène <niels.martignene@protonmail.com>
2
+ //
3
+ // This program is free software: you can redistribute it and/or modify
4
+ // it under the terms of the GNU General Public License as published by
5
+ // the Free Software Foundation, either version 3 of the License, or
6
+ // (at your option) any later version.
7
+ //
8
+ // This program is distributed in the hope that it will be useful,
9
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ // GNU General Public License for more details.
12
+ //
13
+ // You should have received a copy of the GNU General Public License
14
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ window.addEventListener('load', e => {
17
+ initDeploy();
18
+ initMenu();
19
+ initSide();
20
+ initScroll();
21
+
22
+ document.documentElement.classList.remove('nojs');
23
+ document.documentElement.classList.add('js');
24
+ });
25
+
26
+ function initDeploy() {
27
+ let deploy = document.querySelector('#deploy');
28
+
29
+ deploy.addEventListener('click', e => {
30
+ let top = document.querySelector('nav#top');
31
+ top.classList.toggle('active');
32
+ });
33
+ }
34
+
35
+ function initMenu() {
36
+ let items = document.querySelectorAll('nav#top li');
37
+
38
+ document.body.addEventListener('click', e => {
39
+ if (e.target.tagName == 'DIV' && findParent(e.target, el => el.id == 'top'))
40
+ return;
41
+
42
+ // Expand top menu categories
43
+ {
44
+ let target = findParent(e.target, el => el.tagName == 'LI');
45
+
46
+ if (target?.querySelector('div') != null) {
47
+ for (let item of items) {
48
+ if (item == target) {
49
+ item.classList.toggle('active');
50
+ } else {
51
+ item.classList.remove('active');
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ if (e.target.tagName == 'A' && e.target.getAttribute('href') == '#')
58
+ e.preventDefault();
59
+ });
60
+ }
61
+
62
+ function initSide() {
63
+ // Find all side menu items, and the pointed to elements
64
+ let links = [].slice.call(document.querySelectorAll('nav#side a'));
65
+ let items = [].slice.call(links).map(link => {
66
+ let anchor = document.querySelector(link.getAttribute('href'));
67
+ return [link, anchor];
68
+ });
69
+ if (!items.length)
70
+ return;
71
+
72
+ let pending_request = false;
73
+ let active_idx = null;
74
+ function highlight(idx) {
75
+ if (pending_request)
76
+ return;
77
+
78
+ window.requestAnimationFrame(() => {
79
+ pending_request = false;
80
+
81
+ if (idx !== active_idx) {
82
+ if (active_idx !== null)
83
+ items[active_idx][0].classList.remove('active');
84
+ items[idx][0].classList.add('active');
85
+ active_idx = idx;
86
+ }
87
+ });
88
+ pending_request = true;
89
+ }
90
+
91
+ // Event handlers, for clicks
92
+ let ignore_scroll = false;
93
+ function highlightOnClick(idx) {
94
+ highlight(idx);
95
+ setTimeout(() => { ignore_scroll = false; }, 50);
96
+ ignore_scroll = true;
97
+ }
98
+ function highlightOnScroll() {
99
+ if (ignore_scroll)
100
+ return;
101
+
102
+ let idx;
103
+ for (idx = 0; idx < items.length; idx++) {
104
+ let rect = items[idx][1].getBoundingClientRect();
105
+ if (rect.top >= 50)
106
+ break;
107
+ }
108
+ if (idx)
109
+ idx--;
110
+
111
+ highlight(idx);
112
+ }
113
+
114
+ // The scroll handler is not enough because it does not work for
115
+ // small sections at the end of the page.
116
+ for (let i = 0; i < items.length; i++) {
117
+ items[i][0].addEventListener('click', highlightOnClick.bind(this, i));
118
+ }
119
+
120
+ // Enable only on big screens, when the side menu is fixed
121
+ let mql = window.matchMedia('(min-width: 801px)');
122
+ if (mql.matches) {
123
+ window.addEventListener('scroll', highlightOnScroll);
124
+ highlightOnScroll();
125
+ }
126
+ mql.addListener(mql => {
127
+ if (mql.matches) {
128
+ window.addEventListener('scroll', highlightOnScroll);
129
+ highlightOnScroll();
130
+ } else {
131
+ window.removeEventListener('scroll', highlightOnScroll);
132
+ }
133
+ });
134
+ }
135
+
136
+ function initScroll() {
137
+ window.addEventListener('scroll', adjust_top);
138
+ adjust_top();
139
+
140
+ function adjust_top() {
141
+ let top = document.querySelector('nav#top');
142
+ top.classList.toggle('border', window.pageYOffset >= 20);
143
+ }
144
+ }
145
+
146
+ function findParent(el, func) {
147
+ while (el && !func(el))
148
+ el = el.parentElement;
149
+ return el;
150
+ }