koffi 2.9.1 → 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 (86) hide show
  1. package/CHANGELOG.md +51 -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_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_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_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_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.js +2 -2
  48. package/indirect.js +2 -2
  49. package/package.json +2 -2
  50. package/src/koffi/src/call.cc +2 -0
  51. package/doc/Makefile +0 -20
  52. package/doc/benchmarks.xlsx +0 -0
  53. package/doc/changelog.md +0 -5
  54. package/doc/conf.py +0 -118
  55. package/doc/index.rst +0 -47
  56. package/doc/make.bat +0 -35
  57. package/doc/poetry.lock +0 -521
  58. package/doc/pyproject.toml +0 -19
  59. package/doc/static/bench_linux.png +0 -0
  60. package/doc/static/bench_windows.png +0 -0
  61. package/doc/static/custom.css +0 -70
  62. package/doc/static/node_c.webp +0 -0
  63. package/doc/static/opensans/LICENSE.txt +0 -202
  64. package/doc/static/opensans/OpenSans.css +0 -39
  65. package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff +0 -0
  66. package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff2 +0 -0
  67. package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff +0 -0
  68. package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff2 +0 -0
  69. package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff +0 -0
  70. package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff2 +0 -0
  71. package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff +0 -0
  72. package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff2 +0 -0
  73. package/doc/static/perf_linux_20220623.png +0 -0
  74. package/doc/static/perf_linux_20220623_2.png +0 -0
  75. package/doc/static/perf_linux_20220627.png +0 -0
  76. package/doc/static/perf_linux_20220628.png +0 -0
  77. package/doc/static/perf_linux_20220812.png +0 -0
  78. package/doc/static/perf_windows_20220623.png +0 -0
  79. package/doc/static/perf_windows_20220623_2.png +0 -0
  80. package/doc/static/perf_windows_20220627.png +0 -0
  81. package/doc/static/perf_windows_20220628.png +0 -0
  82. package/doc/static/perf_windows_20220812.png +0 -0
  83. package/doc/templates/badges.html +0 -7
  84. package/doc/templates/logo.html +0 -3
  85. /package/doc/static/{perf_linux_20231028.png → perf_linux.png} +0 -0
  86. /package/doc/static/{perf_windows_20231028.png → perf_windows.png} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,9 +1,17 @@
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
+
7
15
  #### Koffi 2.9.1 (2024-09-23)
8
16
 
9
17
  - Fix x86 32-bit support regression in 2.9.0
@@ -21,9 +29,8 @@
21
29
 
22
30
  - Work around MSVC compiler bug introduced in Visual Studio 17.10
23
31
 
24
- ```{warning}
32
+ > [!WARNING]
25
33
  Use on platforms without pre-built binaries is broken in Koffi 2.8.10, skip this version.
26
- ```
27
34
 
28
35
  #### Koffi 2.8.9 (2024-05-17)
29
36
 
@@ -39,7 +46,7 @@ Use on platforms without pre-built binaries is broken in Koffi 2.8.10, skip this
39
46
 
40
47
  #### Koffi 2.8.6 (2024-04-12)
41
48
 
42
- - Support [loading library](functions.md#loading-options) with RTLD_DEEPBIND where supported
49
+ - Support [loading library](functions#loading-options) with RTLD_DEEPBIND where supported
43
50
 
44
51
  #### Koffi 2.8.5 (2024-04-11)
45
52
 
@@ -51,13 +58,12 @@ Use on platforms without pre-built binaries is broken in Koffi 2.8.10, skip this
51
58
 
52
59
  - Use simpler workaround for Node 20.12+ and 21.6+ to avoid excessive memory use
53
60
 
54
- ```{warning}
55
- Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
56
- ```
61
+ > [!WARNING]
62
+ > Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
57
63
 
58
64
  #### Koffi 2.8.2 (2024-04-07)
59
65
 
60
- - 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
61
67
 
62
68
  #### Koffi 2.8.1 (2024-04-04)
63
69
 
@@ -66,7 +72,7 @@ Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
66
72
  #### Koffi 2.8.0 (2024-02-12)
67
73
 
68
74
  - Support pushing pointers for string arguments
69
- - Add `koffi.alloc()` for [stable pointers](output.md#stable-pointers)
75
+ - Add `koffi.alloc()` for [stable pointers](output#stable-pointers)
70
76
 
71
77
  ### Koffi 2.7
72
78
 
@@ -89,13 +95,13 @@ Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
89
95
 
90
96
  #### Koffi 2.7.1 (2024-01-02)
91
97
 
92
- - 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)
93
99
  - Refuse type specifiers with invalid tokens at the end (previously ignored)
94
100
 
95
101
  #### Koffi 2.7.0 (2023-12-21)
96
102
 
97
- - Support alternative [callback calling convention](callbacks.md#callback-types) in classic syntax
98
- - 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
99
105
  - Drop unused "internal" property from Koffi
100
106
 
101
107
  ### Koffi 2.6
@@ -107,7 +113,7 @@ Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
107
113
  #### Koffi 2.6.11 (2023-12-05)
108
114
 
109
115
  - Speed up resolving simple and often used type names
110
- - 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)
111
117
 
112
118
  #### Koffi 2.6.10 (2023-11-29)
113
119
 
@@ -120,9 +126,8 @@ Some pre-built binaries are missing in Koffi 2.8.3, skip this version.
120
126
  - Show detected version of Node when not adequate
121
127
  - Minor documentation fixes
122
128
 
123
- ```{warning}
124
- Loading Win32 system libraries can fail in Koffi 2.6.8, skip this version.
125
- ```
129
+ > [!WARNING]
130
+ > Loading Win32 system libraries can fail in Koffi 2.6.8, skip this version.
126
131
 
127
132
  #### Koffi 2.6.6 (2023-10-28)
128
133
 
@@ -141,9 +146,8 @@ Loading Win32 system libraries can fail in Koffi 2.6.8, skip this version.
141
146
 
142
147
  - Add indirect loading script to help some bundlers
143
148
 
144
- ```{warning}
145
- Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
146
- ```
149
+ > [!WARNING]
150
+ > Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
147
151
 
148
152
  #### Koffi 2.6.1 (2023-09-18)
149
153
 
@@ -154,9 +158,9 @@ Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
154
158
 
155
159
  **New features:**
156
160
 
157
- - Use [koffi.symbol()](variables.md#variable-definitions) to make pointers to exported variables (or other symbols)
158
- - Use [koffi.encode()](variables.md#encode-to-c-memory) to explictly encode data from JS to C memory
159
- - 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
160
164
 
161
165
  **Other changes:**
162
166
 
@@ -173,7 +177,7 @@ Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
173
177
  #### Koffi 2.5.19 (2023-08-29)
174
178
 
175
179
  - Create thread-safe function broker lazily
176
- - 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
177
181
 
178
182
  #### Koffi 2.5.18 (2023-08-27)
179
183
 
@@ -185,9 +189,8 @@ Pre-built binaries don't work correctly in Koffi 2.6.2, skip this version.
185
189
  - Fix DLL error when using Koffi from NW.js on Windows
186
190
  - Simplify NW.js Koffi example
187
191
 
188
- ```{warning}
189
- Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those versions.
190
- ```
192
+ > [!WARNING]
193
+ > Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those versions.
191
194
 
192
195
  #### Koffi 2.5.12 (2023-08-21)
193
196
 
@@ -196,7 +199,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
196
199
 
197
200
  #### Koffi 2.5.11 (2023-08-03)
198
201
 
199
- - Support casting function pointers with [koffi.as()](pointers.md#handling-void-pointers)
202
+ - Support casting function pointers with [koffi.as()](pointers#handling-void-pointers)
200
203
  - Build in C++20 mode
201
204
 
202
205
  #### Koffi 2.5.10 (2023-08-01)
@@ -218,7 +221,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
218
221
  #### Koffi 2.5.8 (2023-07-26)
219
222
 
220
223
  - Add more search paths for native Koffi modules
221
- - Add section [about bundling](start.md#bundling-koffi) to documentation
224
+ - Add section [about bundling](start#bundling-koffi) to documentation
222
225
 
223
226
  #### Koffi 2.5.7 (2023-07-19)
224
227
 
@@ -255,7 +258,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
255
258
 
256
259
  **New features:**
257
260
 
258
- - Support [union types](unions.md)
261
+ - Support [union types](unions)
259
262
 
260
263
  **Other fixes:**
261
264
 
@@ -273,8 +276,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
273
276
 
274
277
  **Main changes:**
275
278
 
276
- - Support [decoding function pointers](functions.md#decode-pointer-to-function) to callable functions
277
- - 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)
278
281
  - Deprecate `koffi.callback` in favor of `koffi.proto`
279
282
 
280
283
  **Other changes:**
@@ -384,9 +387,9 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
384
387
 
385
388
  **Main changes:**
386
389
 
387
- - 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))
388
391
  - Fix crash when using disposable types in output parameters
389
- - Add basic [koffi.stats()](misc.md#usage-statistics) interface
392
+ - Add basic [koffi.stats()](misc#usage-statistics) interface
390
393
 
391
394
  **Other changes:**
392
395
 
@@ -404,8 +407,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
404
407
  **Main changes:**
405
408
 
406
409
  - Allow buffers (TypedArray or ArrayBuffer) values for input and/or output pointer arguments (for polymorphic arguments)
407
- - Support opaque buffers (TypedArray or ArrayBuffer) values in `koffi.decode()` to [decode output buffers](output.md#output-buffers)
408
- - 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)
409
412
 
410
413
  **Other changes:**
411
414
 
@@ -436,7 +439,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
436
439
 
437
440
  **Main fixes:**
438
441
 
439
- - Support transparent [asynchronous callbacks](callbacks.md#asynchronous-callbacks)
442
+ - Support transparent [asynchronous callbacks](callbacks#asynchronous-callbacks)
440
443
  - Expand from a maximum of 16+16 to 1024 callbacks running in parallel
441
444
 
442
445
  **Other fixes:**
@@ -454,8 +457,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
454
457
 
455
458
  **New features:**
456
459
 
457
- - Add [koffi.decode()](callbacks.md#decoding-pointer-arguments) for callback pointer arguments
458
- - 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)
459
462
  - Add `koffi.offsetof()` utility function
460
463
  - Support optional *this* binding in `koffi.register()`
461
464
 
@@ -468,7 +471,7 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
468
471
 
469
472
  #### Koffi 2.1.5 (2022-11-27)
470
473
 
471
- - Add missing README.md file to NPM package
474
+ - Add missing README file to NPM package
472
475
 
473
476
  #### Koffi 2.1.4 (2022-11-25)
474
477
 
@@ -497,8 +500,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
497
500
 
498
501
  **Main changes:**
499
502
 
500
- - Add [koffi.as()](pointers.md#handling-void-pointers) to support polymorphic APIs based on `void *` parameters
501
- - 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`
502
505
  - Accept typed arrays for `void *` parameters
503
506
  - Introduce `koffi.opaque()` to replace `koffi.handle()` (which remains supported until Koffi 3.0)
504
507
  - Support JS Array and TypedArray to fill struct and array pointer members
@@ -521,8 +524,8 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
521
524
 
522
525
  **Major new features:**
523
526
 
524
- - Add [disposable types](pointers.md#disposable-types) for automatic disposal of C values (such as heap-allocated strings)
525
- - 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
526
529
  - Support named pointer types
527
530
  - Support complex type specifications outside of prototype parser
528
531
 
@@ -539,7 +542,9 @@ Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those ve
539
542
  - Change handling of opaque handles, which must be used through pointers
540
543
  - Support all types in `koffi.introspect(type)`
541
544
 
542
- Consult the [migration guide](migration.md) for more information.
545
+ Consult the [migration guide](migration) for more information.
546
+
547
+ ## Koffi 1
543
548
 
544
549
  ### Koffi 1.3
545
550
 
@@ -691,7 +696,7 @@ This entry documents changes since version 1.1.0.
691
696
  - Make sure we have a redzone below the stack for all architectures
692
697
  - Use slower allocation for big objects instead of failing
693
698
 
694
- ## Todo list
699
+ # Todo list
695
700
 
696
701
  The following features and improvements are planned, not necessarily in that order:
697
702
 
Binary file
Binary file
Binary file
Binary file
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
+ }