├── .github └── workflows │ ├── build.yml │ └── publish.yml ├── .gitignore ├── .prettierrc ├── .vscode ├── extensions.json └── launch.json ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── samples └── lighting-menus.ts ├── src ├── common-menus │ ├── index.ts │ ├── qmk_audio.ts │ ├── qmk_backlight.ts │ ├── qmk_backlight_rgblight.ts │ ├── qmk_rgb_matrix.ts │ └── qmk_rgblight.ts ├── index.ts ├── kle-parser.ts ├── lighting-presets.ts ├── menu-types.ts ├── test-definition.json ├── themes.ts ├── transform.ts ├── types.common.ts ├── types.guards.ts ├── types.v2.ts ├── types.v3.ts ├── types │ └── util-inspect.d.ts ├── validate.ts └── validated-types │ ├── keyboard-definition-v2.ts │ ├── keyboard-definition-v3.ts │ ├── via-definition-v2.ts │ └── via-definition-v3.ts ├── test ├── data │ ├── v2_has_simple_encoder.json │ ├── v2_invalid_definition.json │ ├── v2_invalid_label_map.json │ ├── v2_valid_definition.json │ ├── v3_has_simple_encoder.json │ ├── v3_invalid_common_menu.json │ ├── v3_invalid_definition.json │ ├── v3_invalid_label_map.json │ └── v3_valid_definition.json ├── keyboard-definition-validator.v2.test.ts ├── keyboard-definition-validator.v3.test.ts ├── transform.v2.test.ts └── transform.v3.test.ts └── tsconfig.json /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: ['master'] 6 | pull_request: 7 | branches: ['master'] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | matrix: 15 | node-version: [18.x] 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Use Node.js ${{ matrix.node-version }} 20 | uses: actions/setup-node@v3 21 | with: 22 | node-version: ${{ matrix.node-version }} 23 | cache: 'npm' 24 | - run: npm ci 25 | - run: npm run build 26 | - run: npm run test:ci 27 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | publish-npm: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-node@v3 13 | with: 14 | node-version: 18 15 | registry-url: https://registry.npmjs.org/ 16 | - run: npm ci 17 | - run: npm run build 18 | - run: npm run test:ci 19 | - run: npm publish --access public 20 | env: 21 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | src/validated-types/*.validator.ts -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "overrides": [ 3 | { 4 | "files": [".prettierrc", ".babelrc", ".eslintrc", ".stylelintrc"], 5 | "options": { 6 | "parser": "json" 7 | } 8 | } 9 | ], 10 | "bracketSpacing": false, 11 | "singleQuote": true 12 | } 13 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "zixuanchen.vitest-explorer" 5 | ] 6 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "type": "node", 7 | "request": "launch", 8 | "name": "Debug Current Test File", 9 | "autoAttachChildProcesses": true, 10 | "skipFiles": ["/**", "**/node_modules/**"], 11 | "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs", 12 | "args": ["run", "${relativeFile}"], 13 | "smartStep": true, 14 | "console": "integratedTerminal" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This library provides an API and typing for reading VIA keyboard definition files. 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@the-via/reader", 3 | "version": "1.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "git+ssh://git@github.com/the-via/reader.git" 7 | }, 8 | "author": "Olivia ", 9 | "license": "GPL-3.0", 10 | "main": "dist/index.js", 11 | "types": "dist/index.d.ts", 12 | "files": [ 13 | "dist/**/*" 14 | ], 15 | "scripts": { 16 | "build": "npm run validate && npm run fix-util && tsc", 17 | "prepack": "npm run build", 18 | "test": "vitest", 19 | "test:update": "vitest -u", 20 | "test:ci": "vitest run", 21 | "fix-util": "replace \"import {inspect} from 'util';\" \"const inspect = JSON.stringify;\" ./src/validated-types -r --include=\"*.validator.ts\"", 22 | "validate": "typescript-json-validator src/validated-types/keyboard-definition-v3.ts KeyboardDefinitionV3 --noExtraProps --defaultProps=false --strictNullChecks && typescript-json-validator src/validated-types/via-definition-v3.ts VIADefinitionV3 --noExtraProps --defaultProps=false --strictNullChecks && typescript-json-validator src/validated-types/keyboard-definition-v2.ts KeyboardDefinitionV2 --noExtraProps --defaultProps=false --strictNullChecks && typescript-json-validator src/validated-types/via-definition-v2.ts VIADefinitionV2 --noExtraProps --defaultProps=false --strictNullChecks" 23 | }, 24 | "dependencies": { 25 | "invariant": "^2.2.4", 26 | "typescript-json-validator": "2.4.2" 27 | }, 28 | "devDependencies": { 29 | "@types/glob": "^8.0.1", 30 | "@types/invariant": "^2.2.35", 31 | "@types/node": "^18.11.18", 32 | "husky": "^8.0.3", 33 | "replace": "^1.2.2", 34 | "typescript": "4.9.4", 35 | "vite": "^4.0.5", 36 | "vitest": "^0.28.3" 37 | }, 38 | "description": "\"API and typing for reading VIA keyboard definitions\"", 39 | "bugs": { 40 | "url": "https://github.com/the-via/reader/issues" 41 | }, 42 | "homepage": "https://github.com/the-via/reader#readme", 43 | "keywords": [ 44 | "via", 45 | "qmk", 46 | "keyboard" 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /samples/lighting-menus.ts: -------------------------------------------------------------------------------- 1 | import {VIAMenu} from '../src/menu-types'; 2 | 3 | export const WTRGBMenu: VIAMenu = { 4 | label: 'Lighting', 5 | content: [ 6 | { 7 | label: 'General', 8 | content: [ 9 | { 10 | label: 'Brightness', 11 | type: 'range', 12 | // bytes?: 1 (default) 13 | options: [0, 100], 14 | content: ['brightness', 0x00, 0x09], 15 | }, 16 | { 17 | label: 'Effect', 18 | type: 'dropdown', 19 | options: [ 20 | ['All Off', 0], 21 | ['Solid Color 1', 1], 22 | ['Alphas/Mods Color 1/2', 2], 23 | ['Gradient Vertical Color 1/2', 2], 24 | ['Raindrops Color 1/2', 2], 25 | ['Cycle All', 0], 26 | ['Cycle Horizontal', 0], 27 | ['Cycle Vertical', 0], 28 | ['Jellybean Raindrops', 0], 29 | ['Radial All Hues', 0], 30 | ['Radial Color 1', 1], 31 | ], 32 | content: ['effect', 0x00, 0x0a], 33 | }, 34 | { 35 | label: 'Effect Speed', 36 | type: 'range', 37 | options: [0, 3], 38 | content: ['effect_speed', 0x00, 0x0b], 39 | }, 40 | { 41 | showIf: '{effect} != 0', 42 | content: [ 43 | { 44 | label: 'Color 1', 45 | type: 'color', 46 | content: ['color_1', 0x00, 0x0c], 47 | }, 48 | ], 49 | }, 50 | { 51 | showIf: '{effect} == 2 || {effect} == 3 || {effect} == 4', 52 | content: [ 53 | { 54 | label: 'Color 2', 55 | type: 'color', 56 | content: ['color_2', 0x00, 0x0d], 57 | }, 58 | ], 59 | }, 60 | ], 61 | }, 62 | { 63 | label: 'Advanced', 64 | content: [ 65 | { 66 | label: 'Disable LEDs when USB is suspended', 67 | type: 'toggle', 68 | // options: [0,1] <- optional explicit, defaults to this 69 | content: ['backlight_disable_when_usb_suspended', 0x00, 0x07], 70 | }, 71 | { 72 | label: 'LED Sleep Timeout', 73 | type: 'range', 74 | options: [0, 255], 75 | unit: 'mins', 76 | content: ['backlight_disable_after_timeout', 0x00, 0x08], 77 | }, 78 | { 79 | label: 'Caps Lock indicator', 80 | type: 'toggle', 81 | options: [ 82 | [255, 255], 83 | [254, 254], 84 | ], 85 | content: ['backlight_caps_lock_indicator', 0x00, 0x0f], 86 | }, 87 | { 88 | label: 'Caps Lock indicator color', 89 | type: 'color', 90 | showIf: 'backlight_caps_lock_indicator.0 == 254', 91 | content: ['backlight_caps_lock_indicator_color', 0x00, 0x0e], 92 | }, 93 | { 94 | label: 'Layer 1 indicator', 95 | type: 'toggle', 96 | options: [ 97 | [255, 255], 98 | [254, 254], 99 | ], 100 | content: ['backlight_layer_1_indicator', 0x00, 0x11], 101 | }, 102 | { 103 | label: 'Layer 1 indicator color', 104 | type: 'color', 105 | showIf: 'backlight_caps_lock_indicator.0 == 254', 106 | content: ['backlight_layer_1_indicator_color', 0x00, 0x10], 107 | }, 108 | { 109 | label: 'Layer 2 indicator', 110 | type: 'toggle', 111 | options: [ 112 | [255, 255], 113 | [254, 254], 114 | ], 115 | content: ['backlight_layer_1_indicator', 0x00, 0x13], 116 | }, 117 | { 118 | label: 'Layer 2 indicator color', 119 | type: 'color', 120 | showIf: 'backlight_caps_lock_indicator.0 == 254', 121 | content: ['backlight_layer_1_indicator_color', 0x00, 0x12], 122 | }, 123 | { 124 | label: 'Layer 3 indicator', 125 | type: 'toggle', 126 | options: [ 127 | [255, 255], 128 | [254, 254], 129 | ], 130 | content: ['backlight_layer_1_indicator', 0x00, 0x15], 131 | }, 132 | { 133 | label: 'Layer 3 indicator color', 134 | type: 'color', 135 | showIf: 'backlight_caps_lock_indicator.0 == 254', 136 | content: ['backlight_layer_1_indicator_color', 0x00, 0x14], 137 | }, 138 | ], 139 | }, 140 | ], 141 | }; 142 | 143 | export const QMKLightingMenu: VIAMenu = { 144 | label: 'Lighting', 145 | content: [ 146 | { 147 | label: 'General', 148 | content: [ 149 | { 150 | label: 'Backlight', 151 | type: 'toggle', 152 | content: ['backlight', 0x00, 0x0a], 153 | }, 154 | { 155 | showIf: '{backlight', 156 | label: 'Brightness', 157 | type: 'range', 158 | options: [0, 100], 159 | content: ['brightness', 0x00, 0x09], 160 | }, 161 | { 162 | label: 'Underglow effect', 163 | type: 'dropdown', 164 | content: ['underglowEffect', 0x00, 0x81], 165 | options: [ 166 | ['All Off', 0], 167 | ['Solid Color', 1], 168 | ['Breathing 1', 1], 169 | ['Breathing 2', 1], 170 | ['Breathing 3', 1], 171 | ['Breathing 4', 1], 172 | ['Rainbow Mood 1', 0], 173 | ['Rainbow Mood 2', 0], 174 | ['Rainbow Mood 3', 0], 175 | ['Rainbow Swirl 1', 0], 176 | ['Rainbow Swirl 2', 0], 177 | ['Rainbow Swirl 3', 0], 178 | ['Rainbow Swirl 4', 0], 179 | ['Rainbow Swirl 5', 0], 180 | ['Rainbow Swirl 6', 0], 181 | ['Snake 1', 1], 182 | ['Snake 2', 1], 183 | ['Snake 3', 1], 184 | ['Snake 4', 1], 185 | ['Snake 5', 1], 186 | ['Snake 6', 1], 187 | ['Knight 1', 1], 188 | ['Knight 2', 1], 189 | ['Knight 3', 1], 190 | ['Christmas', 1], 191 | ['Gradient 1', 1], 192 | ['Gradient 2', 1], 193 | ['Gradient 3', 1], 194 | ['Gradient 4', 1], 195 | ['Gradient 5', 1], 196 | ['Gradient 6', 1], 197 | ['Gradient 7', 1], 198 | ['Gradient 8', 1], 199 | ['Gradient 9', 1], 200 | ['Gradient 10', 1], 201 | ['RGB Test', 1], 202 | ['Alternating', 1], 203 | ], 204 | }, 205 | { 206 | showIf: '{underglowEffect} != 0', 207 | label: 'Underglow Brightness', 208 | type: 'range', 209 | options: [0, 100], 210 | content: ['underglowBrightness', 0x00, 0x80], 211 | }, 212 | { 213 | showIf: '{underglowEffect} != 0', 214 | label: 'Underglow Effect Speed', 215 | type: 'range', 216 | options: [0, 3], 217 | content: ['underglowEffectSpeed', 0x00, 0x82], 218 | }, 219 | ], 220 | }, 221 | ], 222 | }; 223 | -------------------------------------------------------------------------------- /src/common-menus/index.ts: -------------------------------------------------------------------------------- 1 | import {qmk_audio} from './qmk_audio'; 2 | import {qmk_backlight} from './qmk_backlight'; 3 | import {qmk_backlight_rgblight} from './qmk_backlight_rgblight'; 4 | import {qmk_rgblight} from './qmk_rgblight'; 5 | import {qmk_rgb_matrix} from './qmk_rgb_matrix'; 6 | 7 | export const commonMenus = { 8 | qmk_audio, 9 | qmk_backlight_rgblight, 10 | qmk_backlight, 11 | qmk_rgb_matrix, 12 | qmk_rgblight, 13 | }; 14 | -------------------------------------------------------------------------------- /src/common-menus/qmk_audio.ts: -------------------------------------------------------------------------------- 1 | import {VIAMenu} from '../menu-types'; 2 | 3 | export const qmk_audio: VIAMenu[] = [ 4 | { 5 | label: 'Audio', 6 | content: [ 7 | { 8 | label: 'General', 9 | content: [ 10 | { 11 | label: 'Audio Enable', 12 | type: 'toggle', 13 | content: ['id_qmk_audio_enable', 4, 1], 14 | }, 15 | { 16 | label: 'Audio Clicky Enable', 17 | type: 'toggle', 18 | content: ['id_qmk_audio_clicky_enable', 4, 2], 19 | }, 20 | ], 21 | }, 22 | ], 23 | }, 24 | ]; 25 | -------------------------------------------------------------------------------- /src/common-menus/qmk_backlight.ts: -------------------------------------------------------------------------------- 1 | import {VIAMenu} from '../menu-types'; 2 | 3 | export const qmk_backlight: VIAMenu[] = [ 4 | { 5 | label: 'Lighting', 6 | content: [ 7 | { 8 | label: 'Backlight', 9 | content: [ 10 | { 11 | label: 'Backlight Brightness', 12 | type: 'range', 13 | options: [0, 255], 14 | content: ['id_qmk_backlight_brightness', 1, 1], 15 | }, 16 | { 17 | label: 'Backlight Effect', 18 | type: 'dropdown', 19 | content: ['id_qmk_backlight_effect', 1, 2], 20 | options: [ 21 | ['Off', 0], 22 | ['Breathing', 1], 23 | ], 24 | }, 25 | ], 26 | }, 27 | ], 28 | }, 29 | ]; 30 | -------------------------------------------------------------------------------- /src/common-menus/qmk_backlight_rgblight.ts: -------------------------------------------------------------------------------- 1 | import {VIAMenu} from '../menu-types'; 2 | 3 | export const qmk_backlight_rgblight: VIAMenu[] = [ 4 | { 5 | label: 'Lighting', 6 | content: [ 7 | { 8 | label: 'Backlight', 9 | content: [ 10 | { 11 | label: 'Backlight Brightness', 12 | type: 'range', 13 | options: [0, 255], 14 | content: ['id_qmk_backlight_brightness', 1, 1], 15 | }, 16 | { 17 | label: 'Backlight Effect', 18 | type: 'dropdown', 19 | content: ['id_qmk_backlight_effect', 1, 2], 20 | options: [ 21 | ['Off', 0], 22 | ['Breathing', 1], 23 | ], 24 | }, 25 | ], 26 | }, 27 | { 28 | label: 'Underglow', 29 | content: [ 30 | { 31 | label: 'Brightness', 32 | type: 'range', 33 | options: [0, 255], 34 | content: ['id_qmk_rgblight_brightness', 2, 1], 35 | }, 36 | { 37 | label: 'Effect', 38 | type: 'dropdown', 39 | content: ['id_qmk_rgblight_effect', 2, 2], 40 | options: [ 41 | 'All Off', 42 | 'Solid Color', 43 | 'Breathing 1', 44 | 'Breathing 2', 45 | 'Breathing 3', 46 | 'Breathing 4', 47 | 'Rainbow Mood 1', 48 | 'Rainbow Mood 2', 49 | 'Rainbow Mood 3', 50 | 'Rainbow Swirl 1', 51 | 'Rainbow Swirl 2', 52 | 'Rainbow Swirl 3', 53 | 'Rainbow Swirl 4', 54 | 'Rainbow Swirl 5', 55 | 'Rainbow Swirl 6', 56 | 'Snake 1', 57 | 'Snake 2', 58 | 'Snake 3', 59 | 'Snake 4', 60 | 'Snake 5', 61 | 'Snake 6', 62 | 'Knight 1', 63 | 'Knight 2', 64 | 'Knight 3', 65 | 'Christmas', 66 | 'Gradient 1', 67 | 'Gradient 2', 68 | 'Gradient 3', 69 | 'Gradient 4', 70 | 'Gradient 5', 71 | 'Gradient 6', 72 | 'Gradient 7', 73 | 'Gradient 8', 74 | 'Gradient 9', 75 | 'Gradient 10', 76 | 'RGB Test', 77 | 'Alternating', 78 | 'Twinkle 1', 79 | 'Twinkle 2', 80 | 'Twinkle 3', 81 | 'Twinkle 4', 82 | 'Twinkle 5', 83 | 'Twinkle 6', 84 | ], 85 | }, 86 | { 87 | showIf: '{id_qmk_rgblight_effect} != 0', 88 | label: 'Effect Speed', 89 | type: 'range', 90 | options: [0, 255], 91 | content: ['id_qmk_rgblight_effect_speed', 2, 3], 92 | }, 93 | { 94 | showIf: 95 | '{id_qmk_rgblight_effect} != 0 && {id_qmk_rgblight_effect} != 35', 96 | label: 'Color', 97 | type: 'color', 98 | content: ['id_qmk_rgblight_color', 2, 4], 99 | }, 100 | ], 101 | }, 102 | ], 103 | }, 104 | ]; 105 | -------------------------------------------------------------------------------- /src/common-menus/qmk_rgb_matrix.ts: -------------------------------------------------------------------------------- 1 | import {VIAMenu} from '../menu-types'; 2 | 3 | export const qmk_rgb_matrix: VIAMenu[] = [ 4 | { 5 | label: 'Lighting', 6 | content: [ 7 | { 8 | label: 'Backlight', 9 | content: [ 10 | { 11 | label: 'Brightness', 12 | type: 'range', 13 | options: [0, 255], 14 | content: ['id_qmk_rgb_matrix_brightness', 3, 1], 15 | }, 16 | { 17 | label: 'Effect', 18 | type: 'dropdown', 19 | content: ['id_qmk_rgb_matrix_effect', 3, 2], 20 | options: [ 21 | 'All Off', 22 | 'Solid Color', 23 | 'Alphas Mods', 24 | 'Gradient Up/Down', 25 | 'Gradient Left/Right', 26 | 'Breathing', 27 | 'Band Sat.', 28 | 'Band Val.', 29 | 'Pinwheel Sat.', 30 | 'Pinwheel Val.', 31 | 'Spiral Sat.', 32 | 'Spiral Val.', 33 | 'Cycle All', 34 | 'Cycle Left/Right', 35 | 'Cycle Up/Down', 36 | 'Rainbow Moving Chevron', 37 | 'Cycle Out/In', 38 | 'Cycle Out/In Dual', 39 | 'Cycle Pinwheel', 40 | 'Cycle Spiral', 41 | 'Dual Beacon', 42 | 'Rainbow Beacon', 43 | 'Rainbow Pinwheels', 44 | 'Raindrops', 45 | 'Jellybean Raindrops', 46 | 'Hue Breathing', 47 | 'Hue Pendulum', 48 | 'Hue Wave', 49 | 'Pixel Rain', 50 | 'Pixel Flow', 51 | 'Pixel Fractal', 52 | 'Typing Heatmap', 53 | 'Digital Rain', 54 | 'Solid Reactive Simple', 55 | 'Solid Reactive', 56 | 'Solid Reactive Wide', 57 | 'Solid Reactive Multi Wide', 58 | 'Solid Reactive Cross', 59 | 'Solid Reactive Multi Cross', 60 | 'Solid Reactive Nexus', 61 | 'Solid Reactive Multi Nexus', 62 | 'Splash', 63 | 'Multi Splash', 64 | 'Solid Splash', 65 | 'Solid Multi Splash', 66 | ], 67 | }, 68 | { 69 | showIf: '{id_qmk_rgb_matrix_effect} != 0', 70 | label: 'Effect Speed', 71 | type: 'range', 72 | options: [0, 255], 73 | content: ['id_qmk_rgb_matrix_effect_speed', 3, 3], 74 | }, 75 | { 76 | showIf: 77 | '{id_qmk_rgb_matrix_effect} != 0 && {id_qmk_rgb_matrix_effect} != 24 && {id_qmk_rgb_matrix_effect} != 28 && {id_qmk_rgb_matrix_effect} != 29 && {id_qmk_rgb_matrix_effect} != 32', 78 | label: 'Color', 79 | type: 'color', 80 | content: ['id_qmk_rgb_matrix_color', 3, 4], 81 | }, 82 | ], 83 | }, 84 | ], 85 | }, 86 | ]; 87 | -------------------------------------------------------------------------------- /src/common-menus/qmk_rgblight.ts: -------------------------------------------------------------------------------- 1 | import {VIAMenu} from '../menu-types'; 2 | 3 | export const qmk_rgblight: VIAMenu[] = [ 4 | { 5 | label: 'Lighting', 6 | content: [ 7 | { 8 | label: 'Underglow', 9 | content: [ 10 | { 11 | label: 'Brightness', 12 | type: 'range', 13 | options: [0, 255], 14 | content: ['id_qmk_rgblight_brightness', 2, 1], 15 | }, 16 | { 17 | label: 'Effect', 18 | type: 'dropdown', 19 | content: ['id_qmk_rgblight_effect', 2, 2], 20 | options: [ 21 | 'All Off', 22 | 'Solid Color', 23 | 'Breathing 1', 24 | 'Breathing 2', 25 | 'Breathing 3', 26 | 'Breathing 4', 27 | 'Rainbow Mood 1', 28 | 'Rainbow Mood 2', 29 | 'Rainbow Mood 3', 30 | 'Rainbow Swirl 1', 31 | 'Rainbow Swirl 2', 32 | 'Rainbow Swirl 3', 33 | 'Rainbow Swirl 4', 34 | 'Rainbow Swirl 5', 35 | 'Rainbow Swirl 6', 36 | 'Snake 1', 37 | 'Snake 2', 38 | 'Snake 3', 39 | 'Snake 4', 40 | 'Snake 5', 41 | 'Snake 6', 42 | 'Knight 1', 43 | 'Knight 2', 44 | 'Knight 3', 45 | 'Christmas', 46 | 'Gradient 1', 47 | 'Gradient 2', 48 | 'Gradient 3', 49 | 'Gradient 4', 50 | 'Gradient 5', 51 | 'Gradient 6', 52 | 'Gradient 7', 53 | 'Gradient 8', 54 | 'Gradient 9', 55 | 'Gradient 10', 56 | 'RGB Test', 57 | 'Alternating', 58 | 'Twinkle 1', 59 | 'Twinkle 2', 60 | 'Twinkle 3', 61 | 'Twinkle 4', 62 | 'Twinkle 5', 63 | 'Twinkle 6', 64 | ], 65 | }, 66 | { 67 | showIf: '{id_qmk_rgblight_effect} != 0', 68 | label: 'Effect Speed', 69 | type: 'range', 70 | options: [0, 255], 71 | content: ['id_qmk_rgblight_effect_speed', 2, 3], 72 | }, 73 | { 74 | showIf: 75 | '{id_qmk_rgblight_effect} != 0 && {id_qmk_rgblight_effect} != 35', 76 | label: 'Color', 77 | type: 'color', 78 | content: ['id_qmk_rgblight_color', 2, 4], 79 | }, 80 | ], 81 | }, 82 | ], 83 | }, 84 | ]; 85 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export {isVIADefinitionV3} from './validated-types/via-definition-v3.validator'; 2 | export {isVIADefinitionV2} from './validated-types/via-definition-v2.validator'; 3 | export { 4 | isKeyboardDefinitionV3, 5 | ValidateFunction, 6 | } from './validated-types/keyboard-definition-v3.validator'; 7 | export {isKeyboardDefinitionV2} from './validated-types/keyboard-definition-v2.validator'; 8 | export * from './transform'; 9 | export * from './kle-parser'; 10 | export * from './types.v3'; 11 | export * from './types.v2'; 12 | export * from './types.common'; 13 | export * from './menu-types'; 14 | export * from './themes'; 15 | export * from './types.guards'; 16 | export * from './validate'; 17 | export * from './common-menus'; 18 | -------------------------------------------------------------------------------- /src/kle-parser.ts: -------------------------------------------------------------------------------- 1 | import invariant from 'invariant'; 2 | const inspect = JSON.stringify; 3 | import { 4 | Formatting, 5 | Cursor, 6 | ColorCount, 7 | Dimensions, 8 | KLEElem, 9 | Rotation, 10 | Result, 11 | VIALayout, 12 | KLELayout, 13 | KeyColorType, 14 | Decal, 15 | VIAKey, 16 | OptionalDimensions, 17 | KLEDimensions, 18 | } from './types.common'; 19 | 20 | type InnerReduceState = Formatting & 21 | OptionalDimensions & 22 | Dimensions & 23 | Rotation & 24 | Decal & { 25 | cursor: Cursor; 26 | colorCount: ColorCount; 27 | res: Result[]; 28 | a: number; 29 | }; 30 | type OuterReduceState = { 31 | cursor: Cursor; 32 | colorCount: ColorCount; 33 | prevRow: Formatting & Rotation & {a: number}; 34 | res: Result[][]; 35 | }; 36 | 37 | const ENCODER_REGEX = /^[eE]\d+\s*$/; 38 | const LED_REGEX = /^[lL]\d+\s*$/; 39 | 40 | export function rawKLEToKLELayout(kle: string): KLELayout { 41 | const kleArr = kle.split(',\n'); 42 | return kleArr.map((row) => 43 | JSON.parse( 44 | row 45 | .replace(/\n/g, '\\n') 46 | .replace(/\\/g, '\\\\') 47 | .replace(/\"\\(?!,)/g, '\\\\') 48 | .replace(/([{,])([A-Za-z][0-9A-Za-z]?)(:)/g, '$1"$2"$3') 49 | ) 50 | ); 51 | } 52 | 53 | export function filterGroups(keys: Result[]) { 54 | // Currently extract out non x,0 groups i.e. always choose the first option 55 | return keys.filter((key) => key.group.option === 0); 56 | } 57 | 58 | // Finds the closest to the top-left corner 59 | export function findPivot(keys: Result[]): Result { 60 | return [...keys].sort((a, b) => { 61 | const yDiff = a.y - b.y; 62 | return yDiff !== 0 ? yDiff : a.x - b.x; 63 | })[0]; 64 | } 65 | 66 | type GroupOptionMap = {[group: string]: {[option: string]: A[]}}; 67 | 68 | function getPivotPoint(a: Result) { 69 | // complicated keys like ISO and BAE combine two rectangles 70 | // so first identify the top-left most rectangle and then get that 71 | // point 72 | 73 | const {x, y, x2 = 0, y2 = 0} = a; 74 | const isSecondRect = y2 === 0 ? x > x + x2 : y2 < 0; 75 | return isSecondRect 76 | ? {x: x + x2, y: y + y2} 77 | : { 78 | x, 79 | y, 80 | }; 81 | } 82 | 83 | // New and improved algorithm: identify top and the leftmost corner of each pivot and 84 | // measure the distance between those two 85 | function calculateDelta2(a: Result, b: Result) { 86 | const aPivotPoint = getPivotPoint(a); 87 | const bPivotPoint = getPivotPoint(b); 88 | return { 89 | x: bPivotPoint.x - aPivotPoint.x, 90 | y: bPivotPoint.y - aPivotPoint.y, 91 | }; 92 | } 93 | 94 | export function getBoundingBox(key: Result) { 95 | const {x2 = 0, y2 = 0, x, y, w = 1, h = 1, r = 0, rx = 0, ry = 0} = key; 96 | const {h2 = h, w2 = w} = key; 97 | const extraArgs: [number, number, number] = [rx, ry, r]; 98 | const box = { 99 | xStart: Math.min(x, x + x2), 100 | yStart: Math.min(y, y + y2), 101 | xEnd: Math.max(x + w, x + x2 + w2), 102 | yEnd: Math.max(y + h, y + y2 + h2), 103 | }; 104 | 105 | const rotatedPoints = [ 106 | {x: box.xStart, y: box.yStart}, 107 | {x: box.xEnd, y: box.yStart}, 108 | {x: box.xStart, y: box.yEnd}, 109 | {x: box.xEnd, y: box.yEnd}, 110 | ].map((p) => applyRotation(p.x, p.y, ...extraArgs)); 111 | return { 112 | xStart: Math.min(...rotatedPoints.map((p) => p.x)), 113 | xEnd: Math.max(...rotatedPoints.map((p) => p.x)), 114 | yStart: Math.min(...rotatedPoints.map((p) => p.y)), 115 | yEnd: Math.max(...rotatedPoints.map((p) => p.y)), 116 | }; 117 | } 118 | 119 | function applyRotation( 120 | x: number, 121 | y: number, 122 | xOrigin: number, 123 | yOrigin: number, 124 | rotation: number 125 | ) { 126 | const rad = (rotation * Math.PI) / 180; 127 | const [normX, normY] = [x - xOrigin, y - yOrigin]; 128 | return { 129 | x: xOrigin + normX * Math.cos(rad) - normY * Math.sin(rad), 130 | y: yOrigin + normX * Math.sin(rad) + normY * Math.cos(rad), 131 | }; 132 | } 133 | 134 | export function extractGroups( 135 | keys: Result[], 136 | origin: {x: number; y: number}, 137 | colorMap: {[k: string]: KeyColorType} 138 | ): GroupOptionMap { 139 | const groups = keys.filter((key) => key.group.key !== -1); 140 | const groupedKeys = groups.reduce( 141 | (p, n) => ({ 142 | ...p, 143 | [n.group.key]: { 144 | ...(p[n.group.key] || {}), 145 | [n.group.option]: ((p[n.group.key] || {})[n.group.option] || []).concat( 146 | n 147 | ), 148 | }, 149 | }), 150 | {} as GroupOptionMap 151 | ); 152 | 153 | // We need two pivots in order to calculate the true placement 154 | // 1. The option 0 pivot + the option n pivot for the rest of them 155 | return Object.entries(groupedKeys).reduce((p, [group, options]) => { 156 | const zeroPivot = findPivot(options[0]); 157 | const normalizedOptions = Object.entries(options).reduce( 158 | (p, [option, results]) => ({ 159 | ...p, 160 | [option]: ((delta) => 161 | results.map((res) => ({ 162 | ...res, 163 | x: res.x - delta.x, 164 | y: res.y - delta.y, 165 | })))(calculateDelta2(zeroPivot, findPivot(results))).map((r) => 166 | resultToVIAKey(r, origin, colorMap) 167 | ), // Resolve key colors and normalize position using origin 168 | }), 169 | {} 170 | ); 171 | return { 172 | ...p, 173 | [group]: normalizedOptions, 174 | }; 175 | }, {}); 176 | } 177 | 178 | // Expects pairs to be in the format "x,y" else throws exception 179 | function extractPair(pair: string) { 180 | if (!pair) { 181 | throw new Error( 182 | `'Row,col' pairs must be placed in the top-left legend in the KLE keymap provided in the definition.` 183 | ); 184 | } 185 | const arr = pair.split(/[,,]/); 186 | invariant(arr.length === 2, `${pair} is not a pair`); 187 | const numArr = arr.map((v) => parseInt(v, 10)); 188 | if (numArr.some((num) => Number.isNaN(num))) { 189 | throw new Error(`Invalid pair: ${pair}`); 190 | } 191 | return numArr; 192 | } 193 | 194 | function resultToVIAKey( 195 | result: Result, 196 | delta: {x: number; y: number}, 197 | colorMap: {[x: string]: KeyColorType} 198 | ): VIAKey { 199 | const {c, t, group, ...partialKey} = result; 200 | return { 201 | ...partialKey, 202 | x: result.x - delta.x, 203 | y: result.y - delta.y, 204 | rx: result.rx - delta.x, 205 | ry: result.ry - delta.y, 206 | color: colorMap[`${c}:${t}`] || KeyColorType.Alpha, 207 | }; 208 | } 209 | 210 | /** Copied from ijprest/kle-serial 211 | */ 212 | const alignmentArr = [ 213 | [0, 6, 2, 8, 9, 11, 3, 5, 1, 4, 7, 10], // 0 = no centering 214 | [1, 7, -1, -1, 9, 11, 4, -1, -1, -1, -1, 10], // 1 = center x 215 | [3, -1, 5, -1, 9, 11, -1, -1, 4, -1, -1, 10], // 2 = center y 216 | [4, -1, -1, -1, 9, 11, -1, -1, -1, -1, -1, 10], // 3 = center x & y 217 | [0, 6, 2, 8, 10, -1, 3, 5, 1, 4, 7, -1], // 4 = center front (default) 218 | [1, 7, -1, -1, 10, -1, 4, -1, -1, -1, -1, -1], // 5 = center front & x 219 | [3, -1, 5, -1, 10, -1, -1, -1, 4, -1, -1, -1], // 6 = center front & y 220 | [4, -1, -1, -1, 10, -1, -1, -1, -1, -1, -1, -1], // 7 = center front & x & y 221 | ]; 222 | 223 | const normalizeLabels = (labels: string, a: number = 0) => { 224 | let normalizedLabels = [] as string[]; 225 | const labelArr = labels.split('\n'); 226 | labelArr.forEach((label, idx) => { 227 | normalizedLabels[alignmentArr[a][idx]] = label.trim(); 228 | }); 229 | 230 | return normalizedLabels; 231 | }; 232 | 233 | enum KeyDataIndex { 234 | LED = 6, 235 | ROWCOL = 0, 236 | GROUP = 8, 237 | ENCODER = 4, 238 | } 239 | 240 | const getKeyData = (normalizedLabels: string[], isDecal?: boolean) => { 241 | let keyData = {} as any; 242 | const fakeRowCol = [-1, -1]; 243 | const fakeGroupOption = [-1, 0]; 244 | 245 | const encoderLabel = normalizedLabels[KeyDataIndex.ENCODER]; 246 | if (encoderLabel && ENCODER_REGEX.test(encoderLabel)) { 247 | keyData['ei'] = +encoderLabel.slice(1); 248 | } 249 | 250 | const ledLabel = normalizedLabels[KeyDataIndex.LED]; 251 | if (ledLabel && LED_REGEX.test(ledLabel)) { 252 | keyData['li'] = +ledLabel.slice(1); 253 | } 254 | 255 | const rowColLabel = normalizedLabels[KeyDataIndex.ROWCOL]; 256 | const [row, col] = 257 | isDecal || (keyData['ei'] !== undefined && !rowColLabel) 258 | ? fakeRowCol 259 | : extractPair(rowColLabel); 260 | 261 | const groupLabel = normalizedLabels[KeyDataIndex.GROUP]; 262 | const [group, option] = groupLabel 263 | ? extractPair(groupLabel) 264 | : fakeGroupOption; 265 | return { 266 | ...keyData, 267 | group: {key: group, option}, 268 | row, 269 | col, 270 | }; 271 | }; 272 | 273 | export function kleLayoutToVIALayout(kle: KLELayout): VIALayout { 274 | const filteredKLE = kle.filter((elem) => Array.isArray(elem)) as KLEElem[][]; 275 | const parsedKLE = filteredKLE.reduce( 276 | (prev: OuterReduceState, kle: KLEElem[]) => { 277 | const parsedRow = kle.reduce( 278 | ( 279 | { 280 | cursor: {x, y}, 281 | res, 282 | c, 283 | h, 284 | t, 285 | r, 286 | d, 287 | rx, 288 | ry, 289 | w, 290 | a, 291 | y2, 292 | x2, 293 | w2, 294 | h2, 295 | colorCount, 296 | }: InnerReduceState, 297 | n 298 | ) => { 299 | // Check if object and apply formatting 300 | if (typeof n !== 'string') { 301 | let obj: InnerReduceState = { 302 | colorCount, 303 | a, 304 | c, 305 | t, 306 | h, 307 | r, 308 | rx, 309 | ry, 310 | res, 311 | d, 312 | w, 313 | cursor: {x, y}, 314 | }; 315 | obj = ( 316 | ['y2', 'x2', 'w2', 'h2', 'r', 'rx', 'ry', 'h', 'w'] as ( 317 | | keyof OptionalDimensions 318 | | keyof KLEDimensions 319 | )[] 320 | ).reduce( 321 | (p, prop) => 322 | typeof n[prop] === 'number' ? {...p, [prop]: n[prop]} : p, 323 | obj 324 | ); 325 | if (typeof n.d === 'boolean') { 326 | obj = {...obj, d: n.d}; 327 | } 328 | if (typeof n.ry === 'number' || typeof n.rx === 'number') { 329 | obj = { 330 | ...obj, 331 | cursor: {...obj.cursor, y: obj.ry}, 332 | }; 333 | } 334 | if (typeof n.y === 'number') { 335 | obj = { 336 | ...obj, 337 | cursor: {...obj.cursor, y: obj.cursor.y + n.y}, 338 | }; 339 | } 340 | if (typeof n.x === 'number') { 341 | obj = { 342 | ...obj, 343 | cursor: {...obj.cursor, x: x + n.x}, 344 | }; 345 | } 346 | if (typeof n.a === 'number') { 347 | obj = {...obj, a: n.a}; 348 | } 349 | if (typeof n.c === 'string') { 350 | obj = {...obj, c: n.c}; 351 | } 352 | if (typeof n.t === 'string') { 353 | obj = {...obj, t: n.t}; 354 | } 355 | return obj as InnerReduceState; 356 | } else if (typeof n === 'string') { 357 | // Keys can currently be 358 | // 1. Matrix 359 | // 2. Matrix + Group 360 | // 3. Decal 361 | // 4. Encoder 362 | // 5. Encoder + Group 363 | // 6. Encoder + Matrix (Encoder with Click) 364 | // 7. Encoder + Matrix + Group (Encoder with Click) 365 | const colorCountKey = `${c}:${t}`; 366 | let currKey: any = {}; 367 | 368 | const keyData = getKeyData(normalizeLabels(n, a), d); 369 | 370 | const newColorCount = { 371 | ...colorCount, 372 | [colorCountKey]: 373 | colorCount[colorCountKey] === undefined 374 | ? 1 375 | : colorCount[colorCountKey] + 1, 376 | }; 377 | currKey = { 378 | ...currKey, 379 | ...keyData, 380 | ...{ 381 | c, 382 | t, 383 | x: x + rx, 384 | y, 385 | r, 386 | rx, 387 | ry, 388 | d, 389 | h, 390 | w, 391 | w2, 392 | y2, 393 | x2, 394 | h2, 395 | }, 396 | }; 397 | 398 | // Reset carry properties 399 | return { 400 | h: 1, 401 | w: 1, 402 | r, 403 | rx, 404 | a, 405 | ry, 406 | c, 407 | d: false, 408 | colorCount: newColorCount, 409 | t, 410 | cursor: {x: x + w, y}, 411 | res: [...res, currKey], 412 | }; 413 | } 414 | return { 415 | a, 416 | c, 417 | t, 418 | h, 419 | d, 420 | r, 421 | w, 422 | rx, 423 | ry, 424 | res, 425 | colorCount, 426 | cursor: {x, y}, 427 | }; 428 | }, 429 | { 430 | ...prev.prevRow, 431 | cursor: prev.cursor, 432 | colorCount: prev.colorCount, 433 | h: 1, 434 | w: 1, 435 | d: false, 436 | res: [], 437 | } 438 | ); 439 | return { 440 | cursor: {x: 0, y: parsedRow.cursor.y + 1}, 441 | colorCount: parsedRow.colorCount, 442 | prevRow: { 443 | c: parsedRow.c, 444 | t: parsedRow.t, 445 | r: parsedRow.r, 446 | rx: parsedRow.rx, 447 | ry: parsedRow.ry, 448 | a: parsedRow.a, 449 | }, 450 | res: [...prev.res, parsedRow.res], 451 | }; 452 | }, 453 | { 454 | cursor: {x: 0, y: 0}, 455 | prevRow: {c: '#cccccc', t: '#000000', r: 0, rx: 0, ry: 0, a: 0}, 456 | res: [], 457 | colorCount: {}, 458 | } 459 | ); 460 | 461 | const {colorCount, res} = parsedKLE; 462 | const colorCountKeys = Object.keys(colorCount); 463 | colorCountKeys.sort((a, b) => colorCount[b] - colorCount[a]); 464 | if (colorCountKeys.length > 3) { 465 | throw new Error( 466 | 'Please correct layout, too many colors:' + '\n' + inspect(colorCount) 467 | ); 468 | } 469 | 470 | const colorMap = { 471 | [colorCountKeys[0]]: KeyColorType.Alpha, 472 | [colorCountKeys[1]]: KeyColorType.Mod, 473 | [colorCountKeys[2]]: KeyColorType.Accent, 474 | }; 475 | 476 | const flatRes = res.flat(); 477 | const defaultRes = filterGroups(flatRes); 478 | const boundingBoxes = defaultRes.map(getBoundingBox); 479 | 480 | const minX = Math.min(...boundingBoxes.map((b) => b.xStart)); 481 | const minY = Math.min(...boundingBoxes.map((b) => b.yStart)); 482 | const width = Math.max(...boundingBoxes.map((b) => b.xEnd)) - minX; 483 | const height = Math.max(...boundingBoxes.map((b) => b.yEnd)) - minY; 484 | const keys = defaultRes 485 | .filter((k) => k.group.key === -1) // Remove option keys 486 | .map((k) => resultToVIAKey(k, {x: minX, y: minY}, colorMap)); 487 | const optionKeys = extractGroups(flatRes, {x: minX, y: minY}, colorMap); 488 | 489 | return {width, height, optionKeys, keys}; 490 | } 491 | -------------------------------------------------------------------------------- /src/lighting-presets.ts: -------------------------------------------------------------------------------- 1 | import { 2 | LightingTypeDefinition, 3 | VIALightingTypeDefinition, 4 | LightingValue, 5 | } from './types.v2'; 6 | import {KeycodeType} from './types.common'; 7 | 8 | export const LightingPreset: { 9 | [K in LightingTypeDefinition]: VIALightingTypeDefinition; 10 | } = { 11 | [LightingTypeDefinition.None]: { 12 | effects: [], 13 | underglowEffects: [], 14 | keycodes: KeycodeType.None, 15 | supportedLightingValues: [], 16 | }, 17 | [LightingTypeDefinition.QMKLighting]: { 18 | effects: [ 19 | ['Off', 0], 20 | ['On', 0], 21 | ], 22 | underglowEffects: [], 23 | keycodes: KeycodeType.QMK, 24 | supportedLightingValues: [ 25 | LightingValue.BACKLIGHT_BRIGHTNESS, 26 | LightingValue.BACKLIGHT_EFFECT, 27 | ], 28 | }, 29 | [LightingTypeDefinition.QMKBacklightRGBLight]: { 30 | effects: [ 31 | ['Off', 0], 32 | ['On', 0], 33 | ], 34 | underglowEffects: [ 35 | ['All Off', 0], 36 | ['Solid Color', 1], 37 | ['Breathing 1', 1], 38 | ['Breathing 2', 1], 39 | ['Breathing 3', 1], 40 | ['Breathing 4', 1], 41 | ['Rainbow Mood 1', 0], 42 | ['Rainbow Mood 2', 0], 43 | ['Rainbow Mood 3', 0], 44 | ['Rainbow Swirl 1', 0], 45 | ['Rainbow Swirl 2', 0], 46 | ['Rainbow Swirl 3', 0], 47 | ['Rainbow Swirl 4', 0], 48 | ['Rainbow Swirl 5', 0], 49 | ['Rainbow Swirl 6', 0], 50 | ['Snake 1', 1], 51 | ['Snake 2', 1], 52 | ['Snake 3', 1], 53 | ['Snake 4', 1], 54 | ['Snake 5', 1], 55 | ['Snake 6', 1], 56 | ['Knight 1', 1], 57 | ['Knight 2', 1], 58 | ['Knight 3', 1], 59 | ['Christmas', 1], 60 | ['Gradient 1', 1], 61 | ['Gradient 2', 1], 62 | ['Gradient 3', 1], 63 | ['Gradient 4', 1], 64 | ['Gradient 5', 1], 65 | ['Gradient 6', 1], 66 | ['Gradient 7', 1], 67 | ['Gradient 8', 1], 68 | ['Gradient 9', 1], 69 | ['Gradient 10', 1], 70 | ['RGB Test', 1], 71 | ['Alternating', 1], 72 | ], 73 | keycodes: KeycodeType.QMK, 74 | supportedLightingValues: [ 75 | LightingValue.BACKLIGHT_BRIGHTNESS, 76 | LightingValue.BACKLIGHT_EFFECT, 77 | LightingValue.QMK_RGBLIGHT_BRIGHTNESS, 78 | LightingValue.QMK_RGBLIGHT_EFFECT, 79 | LightingValue.QMK_RGBLIGHT_EFFECT_SPEED, 80 | LightingValue.QMK_RGBLIGHT_COLOR, 81 | ], 82 | }, 83 | [LightingTypeDefinition.QMKRGBLight]: { 84 | effects: [], 85 | underglowEffects: [ 86 | ['All Off', 0], 87 | ['Solid Color', 1], 88 | ['Breathing 1', 1], 89 | ['Breathing 2', 1], 90 | ['Breathing 3', 1], 91 | ['Breathing 4', 1], 92 | ['Rainbow Mood 1', 0], 93 | ['Rainbow Mood 2', 0], 94 | ['Rainbow Mood 3', 0], 95 | ['Rainbow Swirl 1', 0], 96 | ['Rainbow Swirl 2', 0], 97 | ['Rainbow Swirl 3', 0], 98 | ['Rainbow Swirl 4', 0], 99 | ['Rainbow Swirl 5', 0], 100 | ['Rainbow Swirl 6', 0], 101 | ['Snake 1', 1], 102 | ['Snake 2', 1], 103 | ['Snake 3', 1], 104 | ['Snake 4', 1], 105 | ['Snake 5', 1], 106 | ['Snake 6', 1], 107 | ['Knight 1', 1], 108 | ['Knight 2', 1], 109 | ['Knight 3', 1], 110 | ['Christmas', 1], 111 | ['Gradient 1', 1], 112 | ['Gradient 2', 1], 113 | ['Gradient 3', 1], 114 | ['Gradient 4', 1], 115 | ['Gradient 5', 1], 116 | ['Gradient 6', 1], 117 | ['Gradient 7', 1], 118 | ['Gradient 8', 1], 119 | ['Gradient 9', 1], 120 | ['Gradient 10', 1], 121 | ['RGB Test', 1], 122 | ['Alternating', 1], 123 | ], 124 | keycodes: KeycodeType.QMK, 125 | supportedLightingValues: [ 126 | LightingValue.QMK_RGBLIGHT_BRIGHTNESS, 127 | LightingValue.QMK_RGBLIGHT_EFFECT, 128 | LightingValue.QMK_RGBLIGHT_EFFECT_SPEED, 129 | LightingValue.QMK_RGBLIGHT_COLOR, 130 | ], 131 | }, 132 | [LightingTypeDefinition.WTMonoBacklight]: { 133 | effects: [ 134 | ['All Off', 0], 135 | ['All On', 0], 136 | ['Raindrops', 0], 137 | ], 138 | underglowEffects: [], 139 | keycodes: KeycodeType.WT, 140 | supportedLightingValues: [ 141 | LightingValue.BACKLIGHT_BRIGHTNESS, 142 | LightingValue.BACKLIGHT_EFFECT, 143 | LightingValue.BACKLIGHT_EFFECT_SPEED, 144 | LightingValue.BACKLIGHT_DISABLE_AFTER_TIMEOUT, 145 | LightingValue.BACKLIGHT_DISABLE_WHEN_USB_SUSPENDED, 146 | ], 147 | }, 148 | [LightingTypeDefinition.WTRGBBacklight]: { 149 | effects: [ 150 | ['All Off', 0], 151 | ['Solid Color 1', 1], 152 | ['Alphas/Mods Color 1/2', 2], 153 | ['Gradient Vertical Color 1/2', 2], 154 | ['Raindrops Color 1/2', 2], 155 | ['Cycle All', 0], 156 | ['Cycle Horizontal', 0], 157 | ['Cycle Vertical', 0], 158 | ['Jellybean Raindrops', 0], 159 | ['Radial All Hues', 0], 160 | ['Radial Color 1', 1], 161 | ], 162 | underglowEffects: [], 163 | keycodes: KeycodeType.WT, 164 | supportedLightingValues: [ 165 | LightingValue.BACKLIGHT_BRIGHTNESS, 166 | LightingValue.BACKLIGHT_EFFECT, 167 | LightingValue.BACKLIGHT_EFFECT_SPEED, 168 | LightingValue.BACKLIGHT_DISABLE_AFTER_TIMEOUT, 169 | LightingValue.BACKLIGHT_DISABLE_WHEN_USB_SUSPENDED, 170 | LightingValue.BACKLIGHT_COLOR_1, 171 | LightingValue.BACKLIGHT_COLOR_2, 172 | LightingValue.BACKLIGHT_CAPS_LOCK_INDICATOR_COLOR, 173 | LightingValue.BACKLIGHT_CAPS_LOCK_INDICATOR_ROW_COL, 174 | LightingValue.BACKLIGHT_LAYER_1_INDICATOR_COLOR, 175 | LightingValue.BACKLIGHT_LAYER_1_INDICATOR_ROW_COL, 176 | LightingValue.BACKLIGHT_LAYER_2_INDICATOR_COLOR, 177 | LightingValue.BACKLIGHT_LAYER_2_INDICATOR_ROW_COL, 178 | LightingValue.BACKLIGHT_LAYER_3_INDICATOR_COLOR, 179 | LightingValue.BACKLIGHT_LAYER_3_INDICATOR_ROW_COL, 180 | ], 181 | }, 182 | }; 183 | -------------------------------------------------------------------------------- /src/menu-types.ts: -------------------------------------------------------------------------------- 1 | type Label = { 2 | label: string; 3 | }; 4 | 5 | // A property that describes the byte-length of the setting value 6 | type ByteLength = { 7 | bytes?: 1 | 2 | 3 | 4; // default should be 1 8 | }; 9 | 10 | type RawExpr = string; 11 | 12 | // A property that when present, provides the option of not evaluating the block it represents 13 | type Conditional = { 14 | showIf?: RawExpr; 15 | }; 16 | 17 | // A structure that allows a grouping of items, generally useful for conditionally rendering a block of controls 18 | // that share the same render condition 19 | type Group = Conditional & Content; 20 | 21 | // The "parameter" of the render function 22 | type Content = { 23 | content: A; 24 | }; 25 | 26 | type TextContent = Content; 27 | 28 | // Specifies the get-set command prefix 29 | // For fetching the current value: 30 | // For setting the current value: 31 | type BindableContent = Content; 32 | 33 | // token_id, channel_id, command_id 34 | type CommandDef = [string, number, number]; 35 | 36 | // VIA controls 37 | type NumNumArray = number | number[]; // needed to shoehorn wtrgb enable caps/hhkb/etc lighting for now 38 | 39 | export type Button = { 40 | type: 'button'; 41 | options?: [number]; 42 | }; 43 | 44 | export type Toggle = { 45 | type: 'toggle'; 46 | options?: [NumNumArray, NumNumArray]; 47 | }; 48 | 49 | export type Dropdown = { 50 | type: 'dropdown'; 51 | options: string[] | [string, number, ...number[]][]; 52 | }; 53 | 54 | export type Range = { 55 | type: 'range'; 56 | options: [number, number]; 57 | unit?: string; 58 | }; 59 | 60 | export type Keycode = { 61 | type: 'keycode'; 62 | }; 63 | 64 | export type Color = { 65 | type: 'color'; 66 | }; 67 | 68 | export type ColorPalette = { 69 | type: 'color-palette'; 70 | }; 71 | 72 | // An atomic unit that represents a renderable unit - usually a Control 73 | type Item = Label & Conditional & ByteLength & A; 74 | type Control = Keycode | Color | Toggle | Dropdown | Range | Button; 75 | type UniqueControl = ColorPalette; 76 | // The standard VIA control 77 | export type VIAControlItem = Control & Item; 78 | export type VIAUniqueControlItem = UniqueControl & Item; 79 | // For displaying text like headers or static springs 80 | export type VIATextItem = Item; 81 | 82 | // VIA Groups 83 | export type VIAItem = VIATextItem | VIAControlItem | VIAUniqueControlItem; 84 | export type VIAItemSlice = Group; 85 | export type VIASubmenuSlice = Group; 86 | export type VIASubmenu = Label & Group; 87 | export type VIAMenu = Label & Group; 88 | -------------------------------------------------------------------------------- /src/test-definition.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Tester", 3 | "vendorId": "0x0000", 4 | "productId": "0x0000", 5 | "lighting": "none", 6 | "matrix": {"rows": 1, "cols": 108}, 7 | "layouts": { 8 | "keymap": [ 9 | [ 10 | {"c": "#888888"}, 11 | "0,0", 12 | {"x": 1, "c": "#cccccc"}, 13 | "0,1", 14 | "0,2", 15 | "0,3", 16 | "0,4", 17 | {"x": 0.5, "c": "#aaaaaa"}, 18 | "0,5", 19 | "0,6", 20 | "0,7", 21 | "0,8", 22 | {"x": 0.5, "c": "#cccccc"}, 23 | "0,9", 24 | "0,10", 25 | "0,11", 26 | "0,12", 27 | {"x": 0.25, "c": "#aaaaaa"}, 28 | "0,13", 29 | "0,14", 30 | "0,15", 31 | {"x": 0.25}, 32 | "0,16", 33 | "0,17", 34 | "0,18", 35 | "0,19" 36 | ], 37 | [ 38 | {"y": 0.25, "c": "#cccccc"}, 39 | "0,20", 40 | "0,21", 41 | "0,22", 42 | "0,23", 43 | "0,24", 44 | "0,25", 45 | "0,26", 46 | "0,27", 47 | "0,28", 48 | "0,29", 49 | "0,30", 50 | "0,31", 51 | "0,32", 52 | {"c": "#aaaaaa", "w": 2}, 53 | "0,33", 54 | {"x": 0.25}, 55 | "0,34", 56 | "0,35", 57 | "0,36", 58 | {"x": 0.25}, 59 | "0,37", 60 | "0,38", 61 | "0,39", 62 | "0,40" 63 | ], 64 | [ 65 | {"w": 1.5}, 66 | "0,41", 67 | {"c": "#cccccc"}, 68 | "0,42", 69 | "0,43", 70 | "0,44", 71 | "0,45", 72 | "0,46", 73 | "0,47", 74 | "0,48", 75 | "0,49", 76 | "0,50", 77 | "0,51", 78 | "0,52", 79 | "0,53", 80 | {"w": 1.5}, 81 | "0,54", 82 | {"x": 0.25, "c": "#aaaaaa"}, 83 | "0,55", 84 | "0,56", 85 | "0,57", 86 | {"x": 0.25, "c": "#cccccc"}, 87 | "0,58", 88 | "0,59", 89 | "0,60", 90 | {"c": "#aaaaaa", "h": 2}, 91 | "0,61" 92 | ], 93 | [ 94 | {"w": 1.75}, 95 | "0,62", 96 | {"c": "#cccccc"}, 97 | "0,63", 98 | "0,64", 99 | "0,65", 100 | "0,66", 101 | "0,67", 102 | "0,68", 103 | "0,69", 104 | "0,70", 105 | "0,71", 106 | "0,72", 107 | "0,73", 108 | {"c": "#888888", "w": 2.25}, 109 | "0,74", 110 | {"x": 3.5, "c": "#cccccc"}, 111 | "0,75", 112 | "0,76", 113 | "0,77" 114 | ], 115 | [ 116 | {"c": "#aaaaaa", "w": 2.25}, 117 | "0,78", 118 | {"c": "#cccccc"}, 119 | "0,79", 120 | "0,80", 121 | "0,81", 122 | "0,82", 123 | "0,83", 124 | "0,84", 125 | "0,85", 126 | "0,86", 127 | "0,87", 128 | "0,88", 129 | {"c": "#aaaaaa", "w": 2.75}, 130 | "0,89", 131 | {"x": 1.25}, 132 | "0,90", 133 | {"x": 1.25, "c": "#cccccc"}, 134 | "0,91", 135 | "0,92", 136 | "0,93", 137 | {"c": "#888888", "h": 2}, 138 | "0,94" 139 | ], 140 | [ 141 | {"c": "#aaaaaa", "w": 1.25}, 142 | "0,95", 143 | {"w": 1.25}, 144 | "0,96", 145 | {"w": 1.25}, 146 | "0,97", 147 | {"c": "#cccccc", "w": 6.25}, 148 | "0,98", 149 | {"c": "#aaaaaa", "w": 1.25}, 150 | "0,99", 151 | {"w": 1.25}, 152 | "0,100", 153 | {"w": 1.25}, 154 | "0,101", 155 | {"w": 1.25}, 156 | "0,102", 157 | {"x": 0.25}, 158 | "0,103", 159 | "0,104", 160 | "0,105", 161 | {"x": 0.25, "c": "#cccccc", "w": 2}, 162 | "0,106", 163 | "0,107" 164 | ] 165 | ] 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/themes.ts: -------------------------------------------------------------------------------- 1 | import {ThemeDefinition} from './types.common'; 2 | export const THEMES: {[theme: string]: ThemeDefinition} = { 3 | PROTOLIVIA: { 4 | alpha: { 5 | c: '#505557', 6 | t: '#aeb0b0', 7 | }, 8 | mod: { 9 | c: '#6b7173', 10 | t: '#aeb0b0', 11 | }, 12 | accent: { 13 | c: '#afb0ae', 14 | t: '#505557', 15 | }, 16 | }, 17 | OLIVIA: { 18 | alpha: { 19 | c: '#f0f0f0', 20 | t: '#363434', 21 | }, 22 | mod: { 23 | c: '#363434', 24 | t: '#E8C4B8', 25 | }, 26 | accent: { 27 | c: '#E8C4B8', 28 | t: '#363434', 29 | }, 30 | }, 31 | OLIVIA_DARK: { 32 | alpha: { 33 | c: '#363434', 34 | t: '#E8C4B8', 35 | }, 36 | mod: { 37 | c: '#363434', 38 | t: '#E8C4B8', 39 | }, 40 | accent: { 41 | c: '#E8C4B8', 42 | t: '#363434', 43 | }, 44 | }, 45 | OLIVE: { 46 | alpha: { 47 | t: '#66665A', 48 | c: '#D9D7C4', 49 | }, 50 | mod: { 51 | c: '#66665A', 52 | t: '#9DA183', 53 | }, 54 | accent: { 55 | c: '#9DA183', 56 | t: '#66665A', 57 | }, 58 | }, 59 | OLIVE_DARK: { 60 | alpha: { 61 | c: '#66665A', 62 | t: '#9DA183', 63 | }, 64 | mod: { 65 | c: '#66665A', 66 | t: '#9DA183', 67 | }, 68 | accent: { 69 | c: '#9DA183', 70 | t: '#66665A', 71 | }, 72 | }, 73 | OLNY: { 74 | alpha: { 75 | c: '#c20018', 76 | t: '#cfa174', 77 | }, 78 | mod: { 79 | c: '#c20018', 80 | t: '#cfa174', 81 | }, 82 | accent: { 83 | t: '#c20018', 84 | c: '#cfa174', 85 | }, 86 | }, 87 | }; 88 | 89 | export const getTheme = () => THEMES.OLIVIA_DARK; 90 | -------------------------------------------------------------------------------- /src/transform.ts: -------------------------------------------------------------------------------- 1 | import validateV3 from './validated-types/keyboard-definition-v3.validator'; 2 | import validateV2 from './validated-types/keyboard-definition-v2.validator'; 3 | import {KeyboardDefinitionV3, VIADefinitionV3} from './types.v3'; 4 | import { 5 | KeyboardDefinitionV2, 6 | LightingTypeDefinitionV2, 7 | VIADefinitionV2, 8 | VIALightingTypeDefinition, 9 | } from './types.v2'; 10 | import {LightingPreset} from './lighting-presets'; 11 | import { 12 | validateCommonMenus, 13 | validateKeyBounds, 14 | validateLayouts, 15 | } from './validate'; 16 | 17 | export {VIADefinitionV3, KeyboardDefinitionV3}; 18 | 19 | const getHexHint = (value: string) => { 20 | const borkedHexPattern = /^[Oo]x/; 21 | return value.match(borkedHexPattern) 22 | ? `Did you mean '${value.replace(borkedHexPattern, '0x')}' instead?` 23 | : ''; 24 | }; 25 | 26 | export const getVendorProductId = ({ 27 | productId, 28 | vendorId, 29 | }: Pick): number => { 30 | if (vendorId.toUpperCase() === '0XFEED') { 31 | throw new Error(`'0xFEED' is not a valid vendorId.`); 32 | } 33 | 34 | const parsedVendorId = parseInt(vendorId, 16); 35 | const parsedProductId = parseInt(productId, 16); 36 | 37 | if (isNaN(parsedVendorId)) { 38 | throw new Error( 39 | `vendorId could not be parsed: '${vendorId}'. ${getHexHint(vendorId)}` 40 | ); 41 | } 42 | 43 | if (isNaN(parsedProductId)) { 44 | throw new Error( 45 | `productId could not be parsed: '${productId}'. ${getHexHint(productId)}` 46 | ); 47 | } 48 | 49 | return parsedVendorId * 65536 + parsedProductId; 50 | }; 51 | 52 | export const keyboardDefinitionV3ToVIADefinitionV3 = ( 53 | definition: KeyboardDefinitionV3 54 | ): VIADefinitionV3 => { 55 | const { 56 | name, 57 | menus, 58 | keycodes, 59 | customKeycodes, 60 | matrix, 61 | layouts, 62 | firmwareVersion, 63 | } = validateV3(definition); 64 | 65 | const viaLayout = validateLayouts(layouts); 66 | const {keymap, ...partialLayout} = layouts; 67 | const viaLayouts = { 68 | ...partialLayout, 69 | ...viaLayout, 70 | }; 71 | validateKeyBounds(matrix, viaLayouts); 72 | validateCommonMenus(menus ?? []); 73 | 74 | return { 75 | name, 76 | vendorProductId: getVendorProductId(definition), 77 | firmwareVersion: firmwareVersion ?? 0, 78 | menus: menus ?? [], 79 | keycodes: keycodes ?? [], 80 | customKeycodes, 81 | matrix, 82 | layouts: viaLayouts, 83 | }; 84 | }; 85 | 86 | export const keyboardDefinitionV2ToVIADefinitionV2 = ( 87 | definition: KeyboardDefinitionV2 88 | ): VIADefinitionV2 => { 89 | const { 90 | name, 91 | customFeatures, 92 | customMenus, 93 | customKeycodes, 94 | lighting, 95 | matrix, 96 | layouts, 97 | } = validateV2(definition); 98 | 99 | const viaLayout = validateLayouts(layouts); 100 | const {keymap, ...partialLayout} = layouts; 101 | const viaLayouts = { 102 | ...partialLayout, 103 | ...viaLayout, 104 | }; 105 | validateKeyBounds(matrix, viaLayouts); 106 | return { 107 | name, 108 | lighting, 109 | layouts: viaLayouts, 110 | matrix, 111 | customFeatures, 112 | customKeycodes, 113 | customMenus, 114 | vendorProductId: getVendorProductId(definition), 115 | }; 116 | }; 117 | 118 | export const getLightingDefinition = ( 119 | definition: LightingTypeDefinitionV2 120 | ): VIALightingTypeDefinition => 121 | typeof definition === 'string' 122 | ? LightingPreset[definition] 123 | : {...LightingPreset[definition.extends], ...definition}; 124 | -------------------------------------------------------------------------------- /src/types.common.ts: -------------------------------------------------------------------------------- 1 | import {VIADefinitionV2} from './types.v2'; 2 | import {VIADefinitionV3} from './types.v3'; 3 | 4 | export type Rotation = { 5 | r: number; 6 | rx: number; 7 | ry: number; 8 | }; 9 | 10 | export type KLEDimensions = Rotation & { 11 | a: number; 12 | x: number; 13 | w: number; 14 | h: number; 15 | y: number; 16 | }; 17 | 18 | export type OptionalDimensions = Partial<{ 19 | x2: number; 20 | y2: number; 21 | h2: number; 22 | w2: number; 23 | }>; 24 | 25 | export type Ghosted = { 26 | g: boolean; 27 | }; 28 | 29 | export type Stepped = { 30 | l: boolean; 31 | }; 32 | 33 | export type Homing = { 34 | n: boolean; 35 | }; 36 | 37 | export type Decal = { 38 | d: boolean; 39 | }; 40 | 41 | export type TextSize = { 42 | f: number; // default text size 43 | f2: number; 44 | fa: number[]; 45 | }; 46 | 47 | export type Profile = { 48 | p: string; 49 | }; 50 | 51 | export type SwitchInfo = { 52 | sm: string; // switch mount 53 | sb: string; // switch brand 54 | st: string; // switch type 55 | }; 56 | 57 | export type KeyColor = string; 58 | export type LegendColor = string; 59 | 60 | export type MatrixPosition = { 61 | row: number; 62 | col: number; 63 | ei?: number; 64 | li?: number; 65 | }; 66 | 67 | export type Cursor = {x: number; y: number}; 68 | export type Formatting = {c: KeyColor; t: LegendColor}; 69 | export type Dimensions = { 70 | w: number; 71 | h: number; 72 | }; 73 | export type KLEElem = 74 | | Partial< 75 | KLEDimensions & 76 | OptionalDimensions & 77 | Formatting & 78 | Ghosted & 79 | Stepped & 80 | Homing & 81 | Decal & 82 | TextSize & 83 | Profile & 84 | SwitchInfo 85 | > 86 | | string; 87 | export type ColorCount = {[key: string]: number}; 88 | export type ParsedKLE = { 89 | res: Result[][]; 90 | colorMap: {[k: string]: string}; 91 | }; 92 | 93 | export type GroupMeta = { 94 | group: { 95 | key: number; 96 | option: number; 97 | }; 98 | }; 99 | 100 | export type ThemeDefinition = { 101 | [key in KeyColorType]: Formatting; 102 | }; 103 | 104 | export type Result = {h: number; w: number} & Formatting & 105 | Dimensions & 106 | OptionalDimensions & 107 | Cursor & 108 | Rotation & 109 | MatrixPosition & 110 | Decal & 111 | GroupMeta; 112 | 113 | export type VIAKey = Omit & { 114 | color: KeyColorType; 115 | }; 116 | 117 | export enum KeycodeType { 118 | QMK = 'qmk', 119 | WT = 'wt', 120 | None = 'none', 121 | } 122 | 123 | export enum KeyColorType { 124 | Alpha = 'alpha', 125 | Mod = 'mod', 126 | Accent = 'accent', 127 | } 128 | 129 | export type KLEMeta = { 130 | name?: string; 131 | }; 132 | 133 | export type KLELayoutDefinition = (KLEMeta | (string | KLEElem)[])[]; 134 | 135 | export type KLELayout = (KLEMeta | KLEElem[])[]; 136 | 137 | export type MatrixInfo = { 138 | rows: number; 139 | cols: number; 140 | }; 141 | 142 | /* This specifically does not include code */ 143 | export type CustomKeycode = { 144 | name: string; 145 | title: string; 146 | shortName?: string; 147 | }; 148 | 149 | export type LayoutLabel = string | string[]; 150 | 151 | export type VIALayout = { 152 | width: number; 153 | height: number; 154 | keys: VIAKey[]; 155 | optionKeys: {[g: string]: {[o: string]: VIAKey[]}}; 156 | }; 157 | 158 | export type DefinitionVersionMap = {v2: VIADefinitionV2; v3: VIADefinitionV3}; 159 | export type KeyboardDictionary = Record; 160 | 161 | export type DefinitionVersion = 162 | keyof KeyboardDictionary[keyof KeyboardDictionary]; 163 | 164 | export type KeyboardDefinitionIndex = { 165 | generatedAt: number; 166 | version: string; 167 | theme: ThemeDefinition; 168 | vendorProductIds: {[key in DefinitionVersion]: number[]}; 169 | // The idea here is that anything in 'v2' will have both v2 and v3 defs 170 | // so 'v3' only contains defs that aren't v2 171 | }; 172 | -------------------------------------------------------------------------------- /src/types.guards.ts: -------------------------------------------------------------------------------- 1 | import {VIAMenu} from './menu-types'; 2 | 3 | export function isVIAMenu(value: VIAMenu | string): value is VIAMenu { 4 | const viaMenu = value as VIAMenu; 5 | return viaMenu.label !== undefined && viaMenu.content !== undefined; 6 | } 7 | -------------------------------------------------------------------------------- /src/types.v2.ts: -------------------------------------------------------------------------------- 1 | import {VIAMenu} from './menu-types'; 2 | import { 3 | CustomKeycode, 4 | KeycodeType, 5 | KLELayoutDefinition, 6 | LayoutLabel, 7 | MatrixInfo, 8 | VIAKey, 9 | } from './types.common'; 10 | 11 | export enum LightingValue { 12 | BACKLIGHT_USE_SPLIT_BACKSPACE = 0x01, 13 | BACKLIGHT_USE_SPLIT_LEFT_SHIFT = 0x02, 14 | BACKLIGHT_USE_SPLIT_RIGHT_SHIFT = 0x03, 15 | BACKLIGHT_USE_7U_SPACEBAR = 0x04, 16 | BACKLIGHT_USE_ISO_ENTER = 0x05, 17 | BACKLIGHT_DISABLE_HHKB_BLOCKER_LEDS = 0x06, 18 | BACKLIGHT_DISABLE_WHEN_USB_SUSPENDED = 0x07, 19 | BACKLIGHT_DISABLE_AFTER_TIMEOUT = 0x08, 20 | BACKLIGHT_BRIGHTNESS = 0x09, 21 | BACKLIGHT_EFFECT = 0x0a, 22 | BACKLIGHT_EFFECT_SPEED = 0x0b, 23 | BACKLIGHT_COLOR_1 = 0x0c, 24 | BACKLIGHT_COLOR_2 = 0x0d, 25 | BACKLIGHT_CAPS_LOCK_INDICATOR_COLOR = 0x0e, 26 | BACKLIGHT_CAPS_LOCK_INDICATOR_ROW_COL = 0x0f, 27 | BACKLIGHT_LAYER_1_INDICATOR_COLOR = 0x10, 28 | BACKLIGHT_LAYER_1_INDICATOR_ROW_COL = 0x11, 29 | BACKLIGHT_LAYER_2_INDICATOR_COLOR = 0x12, 30 | BACKLIGHT_LAYER_2_INDICATOR_ROW_COL = 0x13, 31 | BACKLIGHT_LAYER_3_INDICATOR_COLOR = 0x14, 32 | BACKLIGHT_LAYER_3_INDICATOR_ROW_COL = 0x15, 33 | BACKLIGHT_CUSTOM_COLOR = 0x17, 34 | // QMK RGBLIGHT 35 | QMK_RGBLIGHT_BRIGHTNESS = 0x80, 36 | QMK_RGBLIGHT_EFFECT = 0x81, 37 | QMK_RGBLIGHT_EFFECT_SPEED = 0x82, 38 | QMK_RGBLIGHT_COLOR = 0x83, 39 | } 40 | 41 | export enum LightingTypeDefinition { 42 | None = 'none', 43 | QMKLighting = 'qmk_backlight', 44 | QMKRGBLight = 'qmk_rgblight', 45 | QMKBacklightRGBLight = 'qmk_backlight_rgblight', 46 | WTRGBBacklight = 'wt_rgb_backlight', 47 | WTMonoBacklight = 'wt_mono_backlight', 48 | } 49 | 50 | export type KeyboardDefinition = { 51 | name: string; 52 | vendorId: string; 53 | productId: string; 54 | lighting: LightingTypeDefinition; 55 | matrix: MatrixInfo; 56 | layouts: {[name: string]: KLELayoutDefinition}; 57 | }; 58 | 59 | export enum CustomFeaturesV2 { 60 | RotaryEncoder = 'rotary-encoder', 61 | } 62 | 63 | export type KeyboardDefinitionV2 = { 64 | name: string; 65 | vendorId: string; 66 | productId: string; 67 | lighting: LightingTypeDefinitionV2; 68 | matrix: MatrixInfo; 69 | customFeatures?: CustomFeaturesV2[]; 70 | customKeycodes?: CustomKeycode[]; 71 | customMenus?: VIAMenu[]; 72 | layouts: { 73 | keymap: KLELayoutDefinition; 74 | labels?: LayoutLabel[]; 75 | presets?: { 76 | [preset: string]: number[]; 77 | }; 78 | }; 79 | }; 80 | 81 | type ColorsNeededV2 = number; 82 | type EffectTupleV2 = [string, ColorsNeededV2]; 83 | 84 | export type VIALightingTypeDefinition = { 85 | effects: EffectTupleV2[]; 86 | underglowEffects: EffectTupleV2[]; 87 | keycodes: KeycodeType; 88 | supportedLightingValues: LightingValue[]; 89 | }; 90 | 91 | export type CustomLightingTypeDefinition = 92 | Partial & { 93 | extends: LightingTypeDefinition; 94 | }; 95 | 96 | export type LightingTypeDefinitionV2 = 97 | | LightingTypeDefinition 98 | | CustomLightingTypeDefinition; 99 | 100 | export type VIADefinitionV2 = { 101 | name: string; 102 | vendorProductId: number; 103 | lighting: LightingTypeDefinitionV2; 104 | matrix: MatrixInfo; 105 | customFeatures?: CustomFeaturesV2[]; 106 | customKeycodes?: CustomKeycode[]; 107 | customMenus?: VIAMenu[]; 108 | layouts: { 109 | width: number; 110 | height: number; 111 | presets?: { 112 | [preset: string]: number[]; 113 | }; 114 | labels?: LayoutLabel[]; 115 | keys: VIAKey[]; 116 | optionKeys: {[g: string]: {[o: string]: VIAKey[]}}; 117 | }; 118 | }; 119 | -------------------------------------------------------------------------------- /src/types.v3.ts: -------------------------------------------------------------------------------- 1 | import {VIAMenu} from './menu-types'; 2 | import { 3 | VIAKey, 4 | MatrixInfo, 5 | CustomKeycode, 6 | KLELayoutDefinition, 7 | LayoutLabel, 8 | } from './types.common'; 9 | 10 | export enum BuiltInKeycodeModule { 11 | QMKLighting = 'qmk_lighting', 12 | WTLighting = 'wt_lighting', 13 | } 14 | 15 | export const defaultKeycodes: BuiltInKeycodeModule[] = []; 16 | 17 | export type KeyboardDefinitionV3 = { 18 | name: string; 19 | vendorId: string; 20 | productId: string; 21 | firmwareVersion?: number; 22 | matrix: MatrixInfo; 23 | menus?: (VIAMenu | string)[]; 24 | keycodes?: BuiltInKeycodeModule[]; 25 | customKeycodes?: CustomKeycode[]; 26 | layouts: { 27 | keymap: KLELayoutDefinition; 28 | labels?: LayoutLabel[]; 29 | presets?: { 30 | [preset: string]: number[]; 31 | }; 32 | }; 33 | }; 34 | 35 | export type VIADefinitionV3 = { 36 | name: string; 37 | vendorProductId: number; 38 | firmwareVersion: number; 39 | matrix: MatrixInfo; 40 | menus: (VIAMenu | string)[]; 41 | keycodes: BuiltInKeycodeModule[]; 42 | customKeycodes?: CustomKeycode[]; 43 | layouts: { 44 | width: number; 45 | height: number; 46 | presets?: { 47 | [preset: string]: number[]; 48 | }; 49 | labels?: LayoutLabel[]; 50 | keys: VIAKey[]; 51 | optionKeys: {[g: string]: {[o: string]: VIAKey[]}}; 52 | }; 53 | }; 54 | -------------------------------------------------------------------------------- /src/types/util-inspect.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'util-inspect' { 2 | const inspect: any; 3 | export default inspect; 4 | } 5 | -------------------------------------------------------------------------------- /src/validate.ts: -------------------------------------------------------------------------------- 1 | import {commonMenus} from './common-menus'; 2 | import {kleLayoutToVIALayout} from './kle-parser'; 3 | import {VIALayout} from './types.common'; 4 | import {KeyboardDefinitionV3, VIADefinitionV3} from './types.v3'; 5 | 6 | export const validateLayouts = ( 7 | layouts: KeyboardDefinitionV3['layouts'] 8 | ): VIALayout => { 9 | const {labels = [], keymap} = layouts; 10 | const viaLayout = kleLayoutToVIALayout(keymap); 11 | const missingLabels = labels.filter( 12 | (_, idx) => 13 | viaLayout.optionKeys[idx] === undefined || 14 | viaLayout.optionKeys[idx][0] === undefined 15 | ); 16 | if (missingLabels.length > 0) { 17 | throw new Error( 18 | `The KLE is missing the group keys for: ${missingLabels.join(',')}` 19 | ); 20 | } 21 | return viaLayout; 22 | }; 23 | 24 | export const validateKeyBounds = ( 25 | matrix: VIADefinitionV3['matrix'], 26 | layouts: VIADefinitionV3['layouts'] 27 | ): void => { 28 | const {rows, cols} = matrix; 29 | const optionKeys = Object.values(layouts.optionKeys).flatMap((group) => 30 | Object.values(group).flat() 31 | ); 32 | const oobKeys = layouts.keys 33 | .concat(optionKeys) 34 | .filter(({row, col}) => row >= rows || col >= cols); 35 | if (oobKeys.length !== 0) { 36 | throw new Error( 37 | `The following keys reference a row or column outside of dimension defined in the matrix property: ${oobKeys 38 | .map(({row, col}) => `(${row},${col})`) 39 | .join(',')}` 40 | ); 41 | } 42 | }; 43 | 44 | export const validateCommonMenus = (menus: VIADefinitionV3['menus']) => { 45 | const lookupFailedKeys = (menus || []).filter((menu) => { 46 | if (typeof menu === 'string') { 47 | return !Object.keys(commonMenus).includes(menu); 48 | } 49 | return false; 50 | }); 51 | if (lookupFailedKeys.length) { 52 | throw Error( 53 | `Common menus not for found for: ${lookupFailedKeys.join(', ')}` 54 | ); 55 | } 56 | }; 57 | -------------------------------------------------------------------------------- /src/validated-types/keyboard-definition-v2.ts: -------------------------------------------------------------------------------- 1 | import {KeyboardDefinitionV2} from '../types.v2'; 2 | export default KeyboardDefinitionV2; 3 | -------------------------------------------------------------------------------- /src/validated-types/keyboard-definition-v3.ts: -------------------------------------------------------------------------------- 1 | import {KeyboardDefinitionV3} from '../types.v3'; 2 | export default KeyboardDefinitionV3; 3 | -------------------------------------------------------------------------------- /src/validated-types/via-definition-v2.ts: -------------------------------------------------------------------------------- 1 | import {VIADefinitionV2} from '../types.v2'; 2 | export default VIADefinitionV2; 3 | -------------------------------------------------------------------------------- /src/validated-types/via-definition-v3.ts: -------------------------------------------------------------------------------- 1 | import {VIADefinitionV3} from '../types.v3'; 2 | export default VIADefinitionV3; 3 | -------------------------------------------------------------------------------- /test/data/v2_has_simple_encoder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynamis", 3 | "vendorId": "0x6262", 4 | "productId": "0x0001", 5 | "lighting": "qmk_rgblight", 6 | "matrix": { 7 | "rows": 10, 8 | "cols": 7 9 | }, 10 | "layouts": { 11 | "labels": [ 12 | "ISO Enter", 13 | "Split Space", 14 | "Split Left Shift", 15 | "Split Right Shift", 16 | "Split Backspace" 17 | ], 18 | "keymap": [ 19 | [ 20 | { 21 | "x": 15.5 22 | }, 23 | "5,0\n\n\n4,1", 24 | "9,0\n\n\n4,1" 25 | ], 26 | [ 27 | { 28 | "y": 0.25, 29 | "x": 2.5 30 | }, 31 | "0,0", 32 | "0,1", 33 | "0,2", 34 | "0,3", 35 | "0,4", 36 | "0,5", 37 | "0,6", 38 | "5,6", 39 | "5,5", 40 | "5,4", 41 | "5,3", 42 | "5,2", 43 | "5,1", 44 | { 45 | "w": 2 46 | }, 47 | "5,0\n\n\n4,0" 48 | ], 49 | [ 50 | { 51 | "x": 2.5, 52 | "w": 1.5 53 | }, 54 | "1,0", 55 | "1,1", 56 | "1,2", 57 | "1,3", 58 | "1,4", 59 | "1,5", 60 | "1,6", 61 | "6,6", 62 | "6,5", 63 | "6,4", 64 | "6,3", 65 | "6,2", 66 | "6,1", 67 | { 68 | "w": 1.5 69 | }, 70 | "6,0\n\n\n0,0", 71 | { 72 | "x": 4, 73 | "w": 1.25, 74 | "h": 2, 75 | "w2": 1.5, 76 | "h2": 1, 77 | "x2": -0.25 78 | }, 79 | "7,0\n\n\n0,1" 80 | ], 81 | [ 82 | { 83 | "x": 2.5, 84 | "w": 1.75 85 | }, 86 | "2,0", 87 | "2,1", 88 | "2,2", 89 | "2,3", 90 | "2,4", 91 | "2,5", 92 | "2,6", 93 | "7,6", 94 | "7,5", 95 | "7,4", 96 | "7,3", 97 | "7,2", 98 | { 99 | "w": 2.25 100 | }, 101 | "7,0\n\n\n0,0", 102 | { 103 | "x": 3 104 | }, 105 | "7,1\n\n\n0,1" 106 | ], 107 | [ 108 | { 109 | "w": 1.25 110 | }, 111 | "3,0\n\n\n2,1", 112 | "3,1\n\n\n2,1", 113 | { 114 | "x": 0.25, 115 | "w": 2.25 116 | }, 117 | "3,1\n\n\n2,0", 118 | "3,2", 119 | "3,3", 120 | "3,4", 121 | "3,5", 122 | "3,6", 123 | "8,6", 124 | "8,5", 125 | "8,4", 126 | "8,3", 127 | "8,2", 128 | { 129 | "w": 2.75 130 | }, 131 | "8,1\n\n\n3,0", 132 | { 133 | "x": 0.25 134 | }, 135 | "9,1", 136 | { 137 | "a": 7 138 | }, 139 | "e0", 140 | { 141 | "x": 0.25, 142 | "a": 4, 143 | "w": 1.75 144 | }, 145 | "8,1\n\n\n3,1", 146 | "8,0\n\n\n3,1" 147 | ], 148 | [ 149 | { 150 | "x": 2.5, 151 | "w": 1.25 152 | }, 153 | "4,0", 154 | { 155 | "w": 1.25 156 | }, 157 | "4,1", 158 | { 159 | "w": 1.25 160 | }, 161 | "4,2", 162 | { 163 | "w": 6.25 164 | }, 165 | "4,3\n\n\n1,0", 166 | { 167 | "w": 1.25 168 | }, 169 | "4,6", 170 | { 171 | "w": 1.25 172 | }, 173 | "9,6", 174 | { 175 | "w": 1.25 176 | }, 177 | "9,5", 178 | { 179 | "x": 0.5 180 | }, 181 | "9,4", 182 | "9,3", 183 | "9,2" 184 | ], 185 | [ 186 | { 187 | "y": 0.25, 188 | "x": 6.25, 189 | "w": 2.25 190 | }, 191 | "4,3\n\n\n1,1", 192 | { 193 | "w": 1.25 194 | }, 195 | "4,4\n\n\n1,1", 196 | { 197 | "w": 2.75 198 | }, 199 | "4,5\n\n\n1,1" 200 | ] 201 | ] 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /test/data/v2_invalid_definition.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wilba.tech WT60-B", 3 | "vendorId": "0x6582", 4 | "productId": "0x60b0", 5 | "lighting": "wt_rgb_backlight", 6 | "layouts": { 7 | "labels": [ 8 | ["Bottom Row", "HHKB", "Full"] 9 | ], 10 | "keymap": [ 11 | [ 12 | { 13 | "c": "#888888" 14 | }, 15 | "0,0", 16 | { 17 | "c": "#cccccc" 18 | }, 19 | "0,1", 20 | "0,2", 21 | "0,3", 22 | "0,4", 23 | "0,5", 24 | "0,6", 25 | "0,7", 26 | "0,8", 27 | "0,9", 28 | "0,10", 29 | "0,11", 30 | "0,12", 31 | "0,13", 32 | "2,13" 33 | ], 34 | [ 35 | { 36 | "c": "#aaaaaa", 37 | "w": 1.5 38 | }, 39 | "1,0", 40 | { 41 | "c": "#cccccc" 42 | }, 43 | "1,1", 44 | "1,2", 45 | "1,3", 46 | "1,4", 47 | "1,5", 48 | "1,6", 49 | "1,7", 50 | "1,8", 51 | "1,9", 52 | "1,10", 53 | "1,11", 54 | "1,12", 55 | { 56 | "c": "#aaaaaa", 57 | "w": 1.5 58 | }, 59 | "1,13" 60 | ], 61 | [ 62 | { 63 | "w": 1.75 64 | }, 65 | "2,0", 66 | { 67 | "c": "#cccccc" 68 | }, 69 | "2,1", 70 | "2,2", 71 | "2,3", 72 | "2,4", 73 | "2,5", 74 | "2,6", 75 | "2,7", 76 | "2,8", 77 | "2,9", 78 | "2,10", 79 | "2,11", 80 | { 81 | "c": "#888888", 82 | "w": 2.25 83 | }, 84 | "2,12" 85 | ], 86 | [ 87 | { 88 | "c": "#aaaaaa", 89 | "w": 2.25 90 | }, 91 | "3,0", 92 | { 93 | "c": "#cccccc" 94 | }, 95 | "3,2", 96 | "3,3", 97 | "3,4", 98 | "3,5", 99 | "3,6", 100 | "3,7", 101 | "3,8", 102 | "3,9", 103 | "3,10", 104 | "3,11", 105 | { 106 | "c": "#aaaaaa", 107 | "w": 1.75 108 | }, 109 | "3,12", 110 | "3,13" 111 | ], 112 | [ 113 | { 114 | "c": "#cccccc", 115 | "w": 1.5, 116 | "d": true 117 | }, 118 | "\n\n\n0,0", 119 | { 120 | "c": "#aaaaaa" 121 | }, 122 | "4,1\n\n\n0,0", 123 | { 124 | "w": 1.5 125 | }, 126 | "4,2\n\n\n0,0", 127 | { 128 | "c": "#cccccc", 129 | "w": 7 130 | }, 131 | "4,7\n\n\n0,0", 132 | { 133 | "c": "#aaaaaa", 134 | "w": 1.5 135 | }, 136 | "4,11\n\n\n0,0", 137 | "4,12\n\n\n0,0", 138 | { 139 | "c": "#cccccc", 140 | "w": 1.5, 141 | "d": true 142 | }, 143 | "\n\n\n0,0" 144 | ], 145 | [ 146 | { 147 | "y": 0.25, 148 | "c": "#aaaaaa", 149 | "w": 1.5 150 | }, 151 | "4,0\n\n\n0,1", 152 | "4,1\n\n\n0,1", 153 | { 154 | "w": 1.5 155 | }, 156 | "4,2\n\n\n0,1", 157 | { 158 | "c": "#cccccc", 159 | "w": 7 160 | }, 161 | "4,7\n\n\n0,1", 162 | { 163 | "c": "#aaaaaa", 164 | "w": 1.5 165 | }, 166 | "4,11\n\n\n0,1", 167 | "4,12\n\n\n0,1", 168 | { 169 | "w": 1.5 170 | }, 171 | "4,13\n\n\n0,1" 172 | ] 173 | ] 174 | } 175 | } -------------------------------------------------------------------------------- /test/data/v2_invalid_label_map.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wilba.tech WT60-B", 3 | "vendorId": "0x6582", 4 | "productId": "0x60b0", 5 | "lighting": "wt_rgb_backlight", 6 | "matrix": {"rows": 5, "cols": 14}, 7 | "layouts": { 8 | "labels": [["Bottom Row", "HHKB", "Full"]], 9 | "keymap": [ 10 | [ 11 | { 12 | "c": "#cccccc", 13 | "w": 1.5, 14 | "d": true, 15 | "w2": 1.5, 16 | "h2": 1, 17 | "x2": -0.25, 18 | "r": 0, 19 | "rx": 1, 20 | "ry": 2, 21 | "x": 10, 22 | "y": 15, 23 | "y2": 1, 24 | "h": 10, 25 | "g": true, 26 | "l": true, 27 | "n": true, 28 | "f": 3, 29 | "f2": 4, 30 | "fa": [1, 2], 31 | "p": "profile", 32 | "sm": "5 pin", 33 | "sb": "gateron", 34 | "st": "linear", 35 | "a": 1 36 | }, 37 | "0,0", 38 | { 39 | "c": "#cccccc" 40 | }, 41 | "0,1", 42 | "0,2", 43 | "0,3", 44 | "0,4", 45 | "0,5", 46 | "0,6", 47 | "0,7", 48 | "0,8", 49 | "0,9", 50 | "0,10", 51 | "0,11", 52 | "0,12", 53 | "0,13", 54 | "2,13" 55 | ], 56 | [ 57 | { 58 | "c": "#aaaaaa", 59 | "w": 1.5 60 | }, 61 | "1,0", 62 | { 63 | "c": "#cccccc" 64 | }, 65 | "1,1", 66 | "1,2", 67 | "1,3", 68 | "1,4", 69 | "1,5", 70 | "1,6", 71 | "1,7", 72 | "1,8", 73 | "1,9", 74 | "1,10", 75 | "1,11", 76 | "1,12", 77 | { 78 | "c": "#aaaaaa", 79 | "w": 1.5 80 | }, 81 | "1,13" 82 | ], 83 | [ 84 | { 85 | "w": 1.75 86 | }, 87 | "2,0", 88 | { 89 | "c": "#cccccc" 90 | }, 91 | "2,1", 92 | "2,2", 93 | "2,3", 94 | "2,4", 95 | "2,5", 96 | "2,6", 97 | "2,7", 98 | "2,8", 99 | "2,9", 100 | "2,10", 101 | "2,11", 102 | { 103 | "c": "#888888", 104 | "w": 2.25 105 | }, 106 | "2,12" 107 | ], 108 | [ 109 | { 110 | "c": "#aaaaaa", 111 | "w": 2.25 112 | }, 113 | "3,0", 114 | { 115 | "c": "#cccccc" 116 | }, 117 | "3,2", 118 | "3,3", 119 | "3,4", 120 | "3,5", 121 | "3,6", 122 | "3,7", 123 | "3,8", 124 | "3,9", 125 | "3,10", 126 | "3,11", 127 | { 128 | "c": "#aaaaaa", 129 | "w": 1.75 130 | }, 131 | "3,12", 132 | "3,13" 133 | ], 134 | [ 135 | { 136 | "c": "#cccccc", 137 | "w": 1.5, 138 | "d": true, 139 | "w2": 1.5, 140 | "h2": 1, 141 | "x2": -0.25 142 | }, 143 | "\n\n\n0,0", 144 | { 145 | "c": "#aaaaaa" 146 | }, 147 | "4,1\n\n\n0,0", 148 | { 149 | "w": 1.5 150 | }, 151 | "4,2\n\n\n0,0", 152 | { 153 | "c": "#cccccc", 154 | "w": 7 155 | }, 156 | "4,7\n\n\n0,0", 157 | { 158 | "c": "#aaaaaa", 159 | "w": 1.5 160 | }, 161 | "4,11\n\n\n0,0", 162 | "4,12\n\n\n0,0", 163 | { 164 | "c": "#cccccc", 165 | "w": 1.5, 166 | "d": true 167 | }, 168 | "\n\n\n0,0" 169 | ], 170 | [ 171 | { 172 | "y": 0.25, 173 | "c": "#aaaaaa", 174 | "w": 1.5 175 | }, 176 | "4,0\n\n\n0,1", 177 | "4,1\n\n\n0,1", 178 | { 179 | "w": 1.5 180 | }, 181 | "4,2\n\n\n0,1", 182 | { 183 | "c": "#cccccc", 184 | "w": 7 185 | }, 186 | "4,7\n\n\n0,1", 187 | { 188 | "c": "#aaaaaa", 189 | "w": 1.5 190 | }, 191 | "4,11\n\n\n0,1", 192 | "4,12\n\n\n0,1", 193 | { 194 | "w": 1.5 195 | }, 196 | "4,13\n\n\n0,1" 197 | ] 198 | ] 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /test/data/v2_valid_definition.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wilba.tech WT60-B", 3 | "vendorId": "0x6582", 4 | "productId": "0x60b0", 5 | "lighting": "wt_rgb_backlight", 6 | "matrix": {"rows": 5, "cols": 14}, 7 | "layouts": { 8 | "labels": [["Bottom Row", "HHKB", "Full"]], 9 | "keymap": [ 10 | [ 11 | { 12 | "c": "#cccccc", 13 | "w": 1.5, 14 | "d": true, 15 | "w2": 1.5, 16 | "h2": 1, 17 | "x2": -0.25, 18 | "r": 0, 19 | "rx": 1, 20 | "ry": 2, 21 | "x": 10, 22 | "y": 15, 23 | "y2": 1, 24 | "h": 10, 25 | "g": true, 26 | "l": true, 27 | "n": true, 28 | "f": 3, 29 | "f2": 4, 30 | "fa": [1, 2], 31 | "p": "profile", 32 | "sm": "5 pin", 33 | "sb": "gateron", 34 | "st": "linear", 35 | "a": 0 36 | }, 37 | "0,0", 38 | { 39 | "c": "#cccccc" 40 | }, 41 | "0,1", 42 | "0,2", 43 | "0,3", 44 | "0,4", 45 | "0,5", 46 | "0,6", 47 | "0,7", 48 | "0,8", 49 | "0,9", 50 | "0,10", 51 | "0,11", 52 | "0,12", 53 | "0,13", 54 | "2,13" 55 | ], 56 | [ 57 | { 58 | "c": "#aaaaaa", 59 | "w": 1.5 60 | }, 61 | "1,0", 62 | { 63 | "c": "#cccccc" 64 | }, 65 | "1,1", 66 | "1,2", 67 | "1,3", 68 | "1,4", 69 | "1,5", 70 | "1,6", 71 | "1,7", 72 | "1,8", 73 | "1,9", 74 | "1,10", 75 | "1,11", 76 | "1,12", 77 | { 78 | "c": "#aaaaaa", 79 | "w": 1.5 80 | }, 81 | "1,13" 82 | ], 83 | [ 84 | { 85 | "w": 1.75 86 | }, 87 | "2,0", 88 | { 89 | "c": "#cccccc" 90 | }, 91 | "2,1", 92 | "2,2", 93 | "2,3", 94 | "2,4", 95 | "2,5", 96 | "2,6", 97 | "2,7", 98 | "2,8", 99 | "2,9", 100 | "2,10", 101 | "2,11", 102 | { 103 | "c": "#888888", 104 | "w": 2.25 105 | }, 106 | "2,12" 107 | ], 108 | [ 109 | { 110 | "c": "#aaaaaa", 111 | "w": 2.25 112 | }, 113 | "3,0", 114 | { 115 | "c": "#cccccc" 116 | }, 117 | "3,2", 118 | "3,3", 119 | "3,4", 120 | "3,5", 121 | "3,6", 122 | "3,7", 123 | "3,8", 124 | "3,9", 125 | "3,10", 126 | "3,11", 127 | { 128 | "c": "#aaaaaa", 129 | "w": 1.75 130 | }, 131 | "3,12", 132 | "3,13" 133 | ], 134 | [ 135 | { 136 | "c": "#cccccc", 137 | "w": 1.5, 138 | "d": true, 139 | "w2": 1.5, 140 | "h2": 1, 141 | "x2": -0.25 142 | }, 143 | "\n\n\n0,0", 144 | { 145 | "c": "#aaaaaa" 146 | }, 147 | "4,1\n\n\n0,0", 148 | { 149 | "w": 1.5 150 | }, 151 | "4,2\n\n\n0,0", 152 | { 153 | "c": "#cccccc", 154 | "w": 7 155 | }, 156 | "4,7\n\n\n0,0", 157 | { 158 | "c": "#aaaaaa", 159 | "w": 1.5 160 | }, 161 | "4,11\n\n\n0,0", 162 | "4,12\n\n\n0,0", 163 | { 164 | "c": "#cccccc", 165 | "w": 1.5, 166 | "d": true 167 | }, 168 | "\n\n\n0,0" 169 | ], 170 | [ 171 | { 172 | "y": 0.25, 173 | "c": "#aaaaaa", 174 | "w": 1.5 175 | }, 176 | "4,0\n\n\n0,1", 177 | "4,1\n\n\n0,1", 178 | { 179 | "w": 1.5 180 | }, 181 | "4,2\n\n\n0,1", 182 | { 183 | "c": "#cccccc", 184 | "w": 7 185 | }, 186 | "4,7\n\n\n0,1", 187 | { 188 | "c": "#aaaaaa", 189 | "w": 1.5 190 | }, 191 | "4,11\n\n\n0,1", 192 | "4,12\n\n\n0,1", 193 | { 194 | "w": 1.5 195 | }, 196 | "4,13\n\n\n0,1" 197 | ] 198 | ] 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /test/data/v3_has_simple_encoder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynamis", 3 | "vendorId": "0x6262", 4 | "productId": "0x0001", 5 | "keycodes": ["qmk_lighting"], 6 | "menus": ["qmk_rgblight"], 7 | "matrix": {"rows": 10, "cols": 7}, 8 | "layouts": { 9 | "labels": [ 10 | "ISO Enter", 11 | "Split Space", 12 | "Split Left Shift", 13 | "Split Right Shift", 14 | "Split Backspace" 15 | ], 16 | "keymap": [ 17 | [{"x": 15.5}, "5,0\n\n\n4,1", "9,0\n\n\n4,1"], 18 | [ 19 | {"y": 0.25, "x": 2.5}, 20 | "0,0", 21 | "0,1", 22 | "0,2", 23 | "0,3", 24 | "0,4", 25 | "0,5", 26 | "0,6", 27 | "5,6", 28 | "5,5", 29 | "5,4", 30 | "5,3", 31 | "5,2", 32 | "5,1", 33 | {"w": 2}, 34 | "5,0\n\n\n4,0" 35 | ], 36 | [ 37 | {"x": 2.5, "w": 1.5}, 38 | "1,0", 39 | "1,1", 40 | "1,2", 41 | "1,3", 42 | "1,4", 43 | "1,5", 44 | "1,6", 45 | "6,6", 46 | "6,5", 47 | "6,4", 48 | "6,3", 49 | "6,2", 50 | "6,1", 51 | {"w": 1.5}, 52 | "6,0\n\n\n0,0", 53 | {"x": 4, "w": 1.25, "h": 2, "w2": 1.5, "h2": 1, "x2": -0.25}, 54 | "7,0\n\n\n0,1" 55 | ], 56 | [ 57 | {"x": 2.5, "w": 1.75}, 58 | "2,0", 59 | "2,1", 60 | "2,2", 61 | "2,3", 62 | "2,4", 63 | "2,5", 64 | "2,6", 65 | "7,6", 66 | "7,5", 67 | "7,4", 68 | "7,3", 69 | "7,2", 70 | {"w": 2.25}, 71 | "7,0\n\n\n0,0", 72 | {"x": 3}, 73 | "7,1\n\n\n0,1" 74 | ], 75 | [ 76 | {"w": 1.25}, 77 | "3,0\n\n\n2,1", 78 | "3,1\n\n\n2,1", 79 | {"x": 0.25, "w": 2.25}, 80 | "3,1\n\n\n2,0", 81 | "3,2", 82 | "3,3", 83 | "3,4", 84 | "3,5", 85 | "3,6", 86 | "8,6", 87 | "8,5", 88 | "8,4", 89 | "8,3", 90 | "8,2", 91 | {"w": 2.75}, 92 | "8,1\n\n\n3,0", 93 | {"x": 0.25}, 94 | "9,1", 95 | {"a": 7}, 96 | "e0", 97 | {"x": 0.25, "a": 4, "w": 1.75}, 98 | "8,1\n\n\n3,1", 99 | "8,0\n\n\n3,1" 100 | ], 101 | [ 102 | {"x": 2.5, "w": 1.25}, 103 | "4,0", 104 | {"w": 1.25}, 105 | "4,1", 106 | {"w": 1.25}, 107 | "4,2", 108 | {"w": 6.25}, 109 | "4,3\n\n\n1,0", 110 | {"w": 1.25}, 111 | "4,6", 112 | {"w": 1.25}, 113 | "9,6", 114 | {"w": 1.25}, 115 | "9,5", 116 | {"x": 0.5}, 117 | "9,4", 118 | "9,3", 119 | "9,2" 120 | ], 121 | [ 122 | {"y": 0.25, "x": 6.25, "w": 2.25}, 123 | "4,3\n\n\n1,1", 124 | {"w": 1.25}, 125 | "4,4\n\n\n1,1", 126 | {"w": 2.75}, 127 | "4,5\n\n\n1,1" 128 | ] 129 | ] 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /test/data/v3_invalid_common_menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wilba.tech WT60-KH1", 3 | "vendorId": "0x6582", 4 | "productId": "0x0034", 5 | "keycodes": ["wt_lighting"], 6 | "menus": ["wt_rgb_backlight"], 7 | "matrix": {"rows": 5, "cols": 14}, 8 | "layouts": { 9 | "labels": [["Bottom Row", "7U", "HHKB", "WKL"]], 10 | "keymap": [ 11 | [ 12 | { 13 | "c": "#777777" 14 | }, 15 | "0,0", 16 | { 17 | "c": "#cccccc" 18 | }, 19 | "0,1", 20 | "0,2", 21 | "0,3", 22 | "0,4", 23 | "0,5", 24 | "0,6", 25 | "0,7", 26 | "0,8", 27 | "0,9", 28 | "0,10", 29 | "0,11", 30 | "0,12", 31 | "0,13", 32 | "2,13" 33 | ], 34 | [ 35 | { 36 | "c": "#aaaaaa", 37 | "w": 1.5 38 | }, 39 | "1,0", 40 | { 41 | "c": "#cccccc" 42 | }, 43 | "1,1", 44 | "1,2", 45 | "1,3", 46 | "1,4", 47 | "1,5", 48 | "1,6", 49 | "1,7", 50 | "1,8", 51 | "1,9", 52 | "1,10", 53 | "1,11", 54 | "1,12", 55 | { 56 | "c": "#aaaaaa", 57 | "w": 1.5 58 | }, 59 | "1,13" 60 | ], 61 | [ 62 | { 63 | "w": 1.75 64 | }, 65 | "2,0", 66 | { 67 | "c": "#cccccc" 68 | }, 69 | "2,1", 70 | "2,2", 71 | "2,3", 72 | "2,4", 73 | "2,5", 74 | "2,6", 75 | "2,7", 76 | "2,8", 77 | "2,9", 78 | "2,10", 79 | "2,11", 80 | { 81 | "c": "#777777", 82 | "w": 2.25 83 | }, 84 | "2,12" 85 | ], 86 | [ 87 | { 88 | "c": "#aaaaaa", 89 | "w": 2.25 90 | }, 91 | "3,0", 92 | { 93 | "c": "#cccccc" 94 | }, 95 | "3,2", 96 | "3,3", 97 | "3,4", 98 | "3,5", 99 | "3,6", 100 | "3,7", 101 | "3,8", 102 | "3,9", 103 | "3,10", 104 | "3,11", 105 | { 106 | "c": "#aaaaaa", 107 | "w": 1.75 108 | }, 109 | "3,12", 110 | "3,13" 111 | ], 112 | [ 113 | { 114 | "w": 1.5 115 | }, 116 | "4,0\n\n\n0,0", 117 | "4,1\n\n\n0,0", 118 | { 119 | "w": 1.5 120 | }, 121 | "4,2\n\n\n0,0", 122 | { 123 | "c": "#cccccc", 124 | "w": 7 125 | }, 126 | "4,6\n\n\n0,0", 127 | { 128 | "c": "#aaaaaa", 129 | "w": 1.5 130 | }, 131 | "4,11\n\n\n0,0", 132 | "4,12\n\n\n0,0", 133 | { 134 | "w": 1.5 135 | }, 136 | "4,13\n\n\n0,0" 137 | ], 138 | [ 139 | { 140 | "y": 0.25, 141 | "w": 1.5, 142 | "d": true 143 | }, 144 | "4,0\n\n\n0,1", 145 | "4,1\n\n\n0,1", 146 | { 147 | "w": 1.5 148 | }, 149 | "4,2\n\n\n0,1", 150 | { 151 | "c": "#cccccc", 152 | "w": 7 153 | }, 154 | "4,6\n\n\n0,1", 155 | { 156 | "c": "#aaaaaa", 157 | "w": 1.5 158 | }, 159 | "4,11\n\n\n0,1", 160 | "4,12\n\n\n0,1", 161 | { 162 | "w": 1.5, 163 | "d": true 164 | }, 165 | "4,13\n\n\n0,1" 166 | ], 167 | [ 168 | { 169 | "w": 1.5 170 | }, 171 | "4,0\n\n\n0,2", 172 | { 173 | "d": true 174 | }, 175 | "4,1\n\n\n0,2", 176 | { 177 | "w": 1.5 178 | }, 179 | "4,2\n\n\n0,2", 180 | { 181 | "c": "#cccccc", 182 | "w": 7 183 | }, 184 | "4,6\n\n\n0,2", 185 | { 186 | "c": "#aaaaaa", 187 | "w": 1.5 188 | }, 189 | "4,11\n\n\n0,2", 190 | { 191 | "d": true 192 | }, 193 | "4,12\n\n\n0,2", 194 | { 195 | "w": 1.5 196 | }, 197 | "4,13\n\n\n0,2" 198 | ] 199 | ] 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /test/data/v3_invalid_definition.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wilba.tech WT60-B", 3 | "vendorId": "0x6582", 4 | "keycodes": ["wt_lighting"], 5 | "menus": [ 6 | { 7 | "label": "Lighting", 8 | "content": [ 9 | { 10 | "label": "General", 11 | "content": [ 12 | { 13 | "label": "Brightness", 14 | "type": "range", 15 | "content": ["id_brightness", 0, 9], 16 | "options": [0, 255] 17 | }, 18 | { 19 | "label": "Effect", 20 | "type": "dropdown", 21 | "options": [ 22 | "All Off", 23 | "Solid Color 1", 24 | "Alphas/Mods Color 1/2", 25 | "Gradient Vertical Color 1/2", 26 | "Raindrops Color 1/2", 27 | "Cycle All", 28 | "Cycle Horizontal", 29 | "Cycle Vertical", 30 | "Jellybean Raindrops", 31 | "Radial All Hues", 32 | "Radial Color 1" 33 | ], 34 | "content": ["id_effect", 0, 10] 35 | }, 36 | { 37 | "label": "Effect Speed", 38 | "type": "range", 39 | "options": [0, 3], 40 | "content": ["id_effect_speed", 0, 11] 41 | }, 42 | { 43 | "showIf": "{id_effect} == 1 || {id_effect} == 2 || {id_effect} == 3 || {id_effect} == 4 || {id_effect} == 10", 44 | "content": [ 45 | { 46 | "label": "Color 1", 47 | "type": "color", 48 | "content": ["id_color_1", 0, 12] 49 | } 50 | ] 51 | }, 52 | { 53 | "showIf": "{id_effect} == 2 || {id_effect} == 3 || {id_effect} == 4", 54 | "content": [ 55 | { 56 | "label": "Color 2", 57 | "type": "color", 58 | "content": ["id_color_2", 0, 13] 59 | } 60 | ] 61 | } 62 | ] 63 | }, 64 | { 65 | "label": "Advanced", 66 | "content": [ 67 | { 68 | "label": "Disable backlight when USB is suspended", 69 | "type": "toggle", 70 | "content": ["id_disable_when_usb_suspended", 0, 7] 71 | }, 72 | { 73 | "label": "Disable backlight after timeout", 74 | "type": "range", 75 | "options": [0, 255], 76 | "unit": "mins", 77 | "content": ["id_disable_after_timeout", 0, 8] 78 | }, 79 | { 80 | "label": "Caps Lock Indicator", 81 | "type": "toggle", 82 | "options": [ 83 | [255, 0], 84 | [254, 0] 85 | ], 86 | "content": ["id_caps_lock_indicator_row_col", 0, 15] 87 | }, 88 | { 89 | "label": "Caps Lock Indicator Color", 90 | "type": "color", 91 | "showIf": "{id_caps_lock_indicator_row_col.0} == 254", 92 | "content": ["id_caps_lock_indicator_color", 0, 14] 93 | }, 94 | { 95 | "label": "Layer 1 Indicator", 96 | "type": "toggle", 97 | "options": [ 98 | [255, 0], 99 | [254, 0] 100 | ], 101 | "content": ["id_layer_1_indicator_row_col", 0, 17] 102 | }, 103 | { 104 | "label": "Layer 1 Indicator color", 105 | "type": "color", 106 | "showIf": "{id_layer_1_indicator_row_col.0} == 254", 107 | "content": ["id_layer_1_indicator_color", 0, 16] 108 | }, 109 | { 110 | "label": "Layer 2 Indicator", 111 | "type": "toggle", 112 | "options": [ 113 | [255, 0], 114 | [254, 0] 115 | ], 116 | "content": ["id_layer_2_indicator_row_col", 0, 19] 117 | }, 118 | { 119 | "label": "Layer 2 Indicator Color", 120 | "type": "color", 121 | "showIf": "{id_layer_2_indicator_row_col.0} == 254", 122 | "content": ["id_layer_2_indicator_color", 0, 18] 123 | }, 124 | { 125 | "label": "Layer 3 Indicator", 126 | "type": "toggle", 127 | "options": [ 128 | [255, 0], 129 | [254, 0] 130 | ], 131 | "content": ["id_layer_3_indicator_row_col", 0, 21] 132 | }, 133 | { 134 | "label": "Layer 3 Indicator color", 135 | "type": "color", 136 | "showIf": "{id_layer_3_indicator_row_col.0} == 254", 137 | "content": ["id_layer_3_indicator_color", 0, 20] 138 | } 139 | ] 140 | } 141 | ] 142 | } 143 | ], 144 | "matrix": {"rows": 5, "cols": 14}, 145 | "layouts": { 146 | "labels": [["Bottom Row", "HHKB", "Full"]], 147 | "keymap": [ 148 | [ 149 | {"c": "#888888"}, 150 | "0,0", 151 | {"c": "#cccccc"}, 152 | "0,1", 153 | "0,2", 154 | "0,3", 155 | "0,4", 156 | "0,5", 157 | "0,6", 158 | "0,7", 159 | "0,8", 160 | "0,9", 161 | "0,10", 162 | "0,11", 163 | "0,12", 164 | "0,13", 165 | "2,13" 166 | ], 167 | [ 168 | {"c": "#aaaaaa", "w": 1.5}, 169 | "1,0", 170 | {"c": "#cccccc"}, 171 | "1,1", 172 | "1,2", 173 | "1,3", 174 | "1,4", 175 | "1,5", 176 | "1,6", 177 | "1,7", 178 | "1,8", 179 | "1,9", 180 | "1,10", 181 | "1,11", 182 | "1,12", 183 | {"c": "#aaaaaa", "w": 1.5}, 184 | "1,13" 185 | ], 186 | [ 187 | {"w": 1.75}, 188 | "2,0", 189 | {"c": "#cccccc"}, 190 | "2,1", 191 | "2,2", 192 | "2,3", 193 | "2,4", 194 | "2,5", 195 | "2,6", 196 | "2,7", 197 | "2,8", 198 | "2,9", 199 | "2,10", 200 | "2,11", 201 | {"c": "#888888", "w": 2.25}, 202 | "2,12" 203 | ], 204 | [ 205 | {"c": "#aaaaaa", "w": 2.25}, 206 | "3,0", 207 | {"c": "#cccccc"}, 208 | "3,2", 209 | "3,3", 210 | "3,4", 211 | "3,5", 212 | "3,6", 213 | "3,7", 214 | "3,8", 215 | "3,9", 216 | "3,10", 217 | "3,11", 218 | {"c": "#aaaaaa", "w": 1.75}, 219 | "3,12", 220 | "3,13" 221 | ], 222 | [ 223 | {"c": "#cccccc", "w": 1.5, "d": true}, 224 | "\n\n\n0,0", 225 | {"c": "#aaaaaa"}, 226 | "4,1\n\n\n0,0", 227 | {"w": 1.5}, 228 | "4,2\n\n\n0,0", 229 | {"c": "#cccccc", "w": 7}, 230 | "4,7\n\n\n0,0", 231 | {"c": "#aaaaaa", "w": 1.5}, 232 | "4,11\n\n\n0,0", 233 | "4,12\n\n\n0,0", 234 | {"c": "#cccccc", "w": 1.5, "d": true}, 235 | "\n\n\n0,0" 236 | ], 237 | [ 238 | {"y": 0.25, "c": "#aaaaaa", "w": 1.5}, 239 | "4,0\n\n\n0,1", 240 | "4,1\n\n\n0,1", 241 | {"w": 1.5}, 242 | "4,2\n\n\n0,1", 243 | {"c": "#cccccc", "w": 7}, 244 | "4,7\n\n\n0,1", 245 | {"c": "#aaaaaa", "w": 1.5}, 246 | "4,11\n\n\n0,1", 247 | "4,12\n\n\n0,1", 248 | {"w": 1.5}, 249 | "4,13\n\n\n0,1" 250 | ] 251 | ] 252 | } 253 | } -------------------------------------------------------------------------------- /test/data/v3_invalid_label_map.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wilba.tech WT60-B", 3 | "vendorId": "0x6582", 4 | "productId": "0x60b0", 5 | "keycodes": ["wt_lighting"], 6 | "menus": [ 7 | { 8 | "label": "Lighting", 9 | "content": [ 10 | { 11 | "label": "General", 12 | "content": [ 13 | { 14 | "label": "Brightness", 15 | "type": "range", 16 | "content": ["id_brightness", 0, 9], 17 | "options": [0, 255] 18 | }, 19 | { 20 | "label": "Effect", 21 | "type": "dropdown", 22 | "options": [ 23 | "All Off", 24 | "Solid Color 1", 25 | "Alphas/Mods Color 1/2", 26 | "Gradient Vertical Color 1/2", 27 | "Raindrops Color 1/2", 28 | "Cycle All", 29 | "Cycle Horizontal", 30 | "Cycle Vertical", 31 | "Jellybean Raindrops", 32 | "Radial All Hues", 33 | "Radial Color 1" 34 | ], 35 | "content": ["id_effect", 0, 10] 36 | }, 37 | { 38 | "label": "Effect Speed", 39 | "type": "range", 40 | "options": [0, 3], 41 | "content": ["id_effect_speed", 0, 11] 42 | }, 43 | { 44 | "showIf": "{id_effect} == 1 || {id_effect} == 2 || {id_effect} == 3 || {id_effect} == 4 || {id_effect} == 10", 45 | "content": [ 46 | { 47 | "label": "Color 1", 48 | "type": "color", 49 | "content": ["id_color_1", 0, 12] 50 | } 51 | ] 52 | }, 53 | { 54 | "showIf": "{id_effect} == 2 || {id_effect} == 3 || {id_effect} == 4", 55 | "content": [ 56 | { 57 | "label": "Color 2", 58 | "type": "color", 59 | "content": ["id_color_2", 0, 13] 60 | } 61 | ] 62 | } 63 | ] 64 | }, 65 | { 66 | "label": "Advanced", 67 | "content": [ 68 | { 69 | "label": "Disable backlight when USB is suspended", 70 | "type": "toggle", 71 | "content": ["id_disable_when_usb_suspended", 0, 7] 72 | }, 73 | { 74 | "label": "Disable backlight after timeout", 75 | "type": "range", 76 | "options": [0, 255], 77 | "unit": "mins", 78 | "content": ["id_disable_after_timeout", 0, 8] 79 | }, 80 | { 81 | "label": "Caps Lock Indicator", 82 | "type": "toggle", 83 | "options": [ 84 | [255, 0], 85 | [254, 0] 86 | ], 87 | "content": ["id_caps_lock_indicator_row_col", 0, 15] 88 | }, 89 | { 90 | "label": "Caps Lock Indicator Color", 91 | "type": "color", 92 | "showIf": "{id_caps_lock_indicator_row_col.0} == 254", 93 | "content": ["id_caps_lock_indicator_color", 0, 14] 94 | }, 95 | { 96 | "label": "Layer 1 Indicator", 97 | "type": "toggle", 98 | "options": [ 99 | [255, 0], 100 | [254, 0] 101 | ], 102 | "content": ["id_layer_1_indicator_row_col", 0, 17] 103 | }, 104 | { 105 | "label": "Layer 1 Indicator color", 106 | "type": "color", 107 | "showIf": "{id_layer_1_indicator_row_col.0} == 254", 108 | "content": ["id_layer_1_indicator_color", 0, 16] 109 | }, 110 | { 111 | "label": "Layer 2 Indicator", 112 | "type": "toggle", 113 | "options": [ 114 | [255, 0], 115 | [254, 0] 116 | ], 117 | "content": ["id_layer_2_indicator_row_col", 0, 19] 118 | }, 119 | { 120 | "label": "Layer 2 Indicator Color", 121 | "type": "color", 122 | "showIf": "{id_layer_2_indicator_row_col.0} == 254", 123 | "content": ["id_layer_2_indicator_color", 0, 18] 124 | }, 125 | { 126 | "label": "Layer 3 Indicator", 127 | "type": "toggle", 128 | "options": [ 129 | [255, 0], 130 | [254, 0] 131 | ], 132 | "content": ["id_layer_3_indicator_row_col", 0, 21] 133 | }, 134 | { 135 | "label": "Layer 3 Indicator color", 136 | "type": "color", 137 | "showIf": "{id_layer_3_indicator_row_col.0} == 254", 138 | "content": ["id_layer_3_indicator_color", 0, 20] 139 | } 140 | ] 141 | } 142 | ] 143 | } 144 | ], 145 | "matrix": {"rows": 5, "cols": 14}, 146 | "layouts": { 147 | "labels": [["Bottom Row", "HHKB", "Full"]], 148 | "keymap": [ 149 | [ 150 | { 151 | "c": "#cccccc", 152 | "w": 1.5, 153 | "d": true, 154 | "w2": 1.5, 155 | "h2": 1, 156 | "x2": -0.25, 157 | "r": 0, 158 | "rx": 1, 159 | "ry": 2, 160 | "x": 10, 161 | "y": 15, 162 | "y2": 1, 163 | "h": 10, 164 | "g": true, 165 | "l": true, 166 | "n": true, 167 | "f": 3, 168 | "f2": 4, 169 | "fa": [1, 2], 170 | "p": "profile", 171 | "sm": "5 pin", 172 | "sb": "gateron", 173 | "st": "linear", 174 | "a": 1 175 | }, 176 | "0,0", 177 | {"c": "#cccccc"}, 178 | "0,1", 179 | "0,2", 180 | "0,3", 181 | "0,4", 182 | "0,5", 183 | "0,6", 184 | "0,7", 185 | "0,8", 186 | "0,9", 187 | "0,10", 188 | "0,11", 189 | "0,12", 190 | "0,13", 191 | "2,13" 192 | ], 193 | [ 194 | {"c": "#aaaaaa", "w": 1.5}, 195 | "1,0", 196 | {"c": "#cccccc"}, 197 | "1,1", 198 | "1,2", 199 | "1,3", 200 | "1,4", 201 | "1,5", 202 | "1,6", 203 | "1,7", 204 | "1,8", 205 | "1,9", 206 | "1,10", 207 | "1,11", 208 | "1,12", 209 | {"c": "#aaaaaa", "w": 1.5}, 210 | "1,13" 211 | ], 212 | [ 213 | {"w": 1.75}, 214 | "2,0", 215 | {"c": "#cccccc"}, 216 | "2,1", 217 | "2,2", 218 | "2,3", 219 | "2,4", 220 | "2,5", 221 | "2,6", 222 | "2,7", 223 | "2,8", 224 | "2,9", 225 | "2,10", 226 | "2,11", 227 | {"c": "#888888", "w": 2.25}, 228 | "2,12" 229 | ], 230 | [ 231 | {"c": "#aaaaaa", "w": 2.25}, 232 | "3,0", 233 | {"c": "#cccccc"}, 234 | "3,2", 235 | "3,3", 236 | "3,4", 237 | "3,5", 238 | "3,6", 239 | "3,7", 240 | "3,8", 241 | "3,9", 242 | "3,10", 243 | "3,11", 244 | {"c": "#aaaaaa", "w": 1.75}, 245 | "3,12", 246 | "3,13" 247 | ], 248 | [ 249 | {"c": "#cccccc", "w": 1.5, "d": true}, 250 | "\n\n\n0,0", 251 | {"c": "#aaaaaa"}, 252 | "4,1\n\n\n0,0", 253 | {"w": 1.5}, 254 | "4,2\n\n\n0,0", 255 | {"c": "#cccccc", "w": 7}, 256 | "4,7\n\n\n0,0", 257 | {"c": "#aaaaaa", "w": 1.5}, 258 | "4,11\n\n\n0,0", 259 | "4,12\n\n\n0,0", 260 | {"c": "#cccccc", "w": 1.5, "d": true}, 261 | "\n\n\n0,0" 262 | ], 263 | [ 264 | {"y": 0.25, "c": "#aaaaaa", "w": 1.5}, 265 | "4,0\n\n\n0,1", 266 | "4,1\n\n\n0,1", 267 | {"w": 1.5}, 268 | "4,2\n\n\n0,1", 269 | {"c": "#cccccc", "w": 7}, 270 | "4,7\n\n\n0,1", 271 | {"c": "#aaaaaa", "w": 1.5}, 272 | "4,11\n\n\n0,1", 273 | "4,12\n\n\n0,1", 274 | {"w": 1.5}, 275 | "4,13\n\n\n0,1" 276 | ] 277 | ] 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /test/data/v3_valid_definition.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wilba.tech WT60-B", 3 | "vendorId": "0x6582", 4 | "productId": "0x60b0", 5 | "keycodes": ["wt_lighting"], 6 | "menus": [ 7 | { 8 | "label": "Lighting", 9 | "content": [ 10 | { 11 | "label": "General", 12 | "content": [ 13 | { 14 | "label": "Brightness", 15 | "type": "range", 16 | "content": ["id_brightness", 0, 9], 17 | "options": [0, 255] 18 | }, 19 | { 20 | "label": "Effect", 21 | "type": "dropdown", 22 | "options": [ 23 | "All Off", 24 | "Solid Color 1", 25 | "Alphas/Mods Color 1/2", 26 | "Gradient Vertical Color 1/2", 27 | "Raindrops Color 1/2", 28 | "Cycle All", 29 | "Cycle Horizontal", 30 | "Cycle Vertical", 31 | "Jellybean Raindrops", 32 | "Radial All Hues", 33 | "Radial Color 1" 34 | ], 35 | "content": ["id_effect", 0, 10] 36 | }, 37 | { 38 | "label": "Effect Speed", 39 | "type": "range", 40 | "options": [0, 3], 41 | "content": ["id_effect_speed", 0, 11] 42 | }, 43 | { 44 | "showIf": "{id_effect} == 1 || {id_effect} == 2 || {id_effect} == 3 || {id_effect} == 4 || {id_effect} == 10", 45 | "content": [ 46 | { 47 | "label": "Color 1", 48 | "type": "color", 49 | "content": ["id_color_1", 0, 12] 50 | } 51 | ] 52 | }, 53 | { 54 | "showIf": "{id_effect} == 2 || {id_effect} == 3 || {id_effect} == 4", 55 | "content": [ 56 | { 57 | "label": "Color 2", 58 | "type": "color", 59 | "content": ["id_color_2", 0, 13] 60 | } 61 | ] 62 | } 63 | ] 64 | }, 65 | { 66 | "label": "Advanced", 67 | "content": [ 68 | { 69 | "label": "Disable backlight when USB is suspended", 70 | "type": "toggle", 71 | "content": ["id_disable_when_usb_suspended", 0, 7] 72 | }, 73 | { 74 | "label": "Disable backlight after timeout", 75 | "type": "range", 76 | "options": [0, 255], 77 | "unit": "mins", 78 | "content": ["id_disable_after_timeout", 0, 8] 79 | }, 80 | { 81 | "label": "Caps Lock Indicator", 82 | "type": "toggle", 83 | "options": [ 84 | [255, 0], 85 | [254, 0] 86 | ], 87 | "content": ["id_caps_lock_indicator_row_col", 0, 15] 88 | }, 89 | { 90 | "label": "Caps Lock Indicator Color", 91 | "type": "color", 92 | "showIf": "{id_caps_lock_indicator_row_col.0} == 254", 93 | "content": ["id_caps_lock_indicator_color", 0, 14] 94 | }, 95 | { 96 | "label": "Layer 1 Indicator", 97 | "type": "toggle", 98 | "options": [ 99 | [255, 0], 100 | [254, 0] 101 | ], 102 | "content": ["id_layer_1_indicator_row_col", 0, 17] 103 | }, 104 | { 105 | "label": "Layer 1 Indicator color", 106 | "type": "color", 107 | "showIf": "{id_layer_1_indicator_row_col.0} == 254", 108 | "content": ["id_layer_1_indicator_color", 0, 16] 109 | }, 110 | { 111 | "label": "Layer 2 Indicator", 112 | "type": "toggle", 113 | "options": [ 114 | [255, 0], 115 | [254, 0] 116 | ], 117 | "content": ["id_layer_2_indicator_row_col", 0, 19] 118 | }, 119 | { 120 | "label": "Layer 2 Indicator Color", 121 | "type": "color", 122 | "showIf": "{id_layer_2_indicator_row_col.0} == 254", 123 | "content": ["id_layer_2_indicator_color", 0, 18] 124 | }, 125 | { 126 | "label": "Layer 3 Indicator", 127 | "type": "toggle", 128 | "options": [ 129 | [255, 0], 130 | [254, 0] 131 | ], 132 | "content": ["id_layer_3_indicator_row_col", 0, 21] 133 | }, 134 | { 135 | "label": "Layer 3 Indicator color", 136 | "type": "color", 137 | "showIf": "{id_layer_3_indicator_row_col.0} == 254", 138 | "content": ["id_layer_3_indicator_color", 0, 20] 139 | } 140 | ] 141 | } 142 | ] 143 | } 144 | ], 145 | "matrix": {"rows": 5, "cols": 14}, 146 | "layouts": { 147 | "labels": [["Bottom Row", "HHKB", "Full"]], 148 | "keymap": [ 149 | [ 150 | { 151 | "c": "#cccccc", 152 | "w": 1.5, 153 | "d": true, 154 | "w2": 1.5, 155 | "h2": 1, 156 | "x2": -0.25, 157 | "r": 0, 158 | "rx": 1, 159 | "ry": 2, 160 | "x": 10, 161 | "y": 15, 162 | "y2": 1, 163 | "h": 10, 164 | "g": true, 165 | "l": true, 166 | "n": true, 167 | "f": 3, 168 | "f2": 4, 169 | "fa": [1, 2], 170 | "p": "profile", 171 | "sm": "5 pin", 172 | "sb": "gateron", 173 | "st": "linear", 174 | "a": 0 175 | }, 176 | "0,0", 177 | {"c": "#cccccc"}, 178 | "0,1", 179 | "0,2", 180 | "0,3", 181 | "0,4", 182 | "0,5", 183 | "0,6", 184 | "0,7", 185 | "0,8", 186 | "0,9", 187 | "0,10", 188 | "0,11", 189 | "0,12", 190 | "0,13", 191 | "2,13" 192 | ], 193 | [ 194 | {"c": "#aaaaaa", "w": 1.5}, 195 | "1,0", 196 | {"c": "#cccccc"}, 197 | "1,1", 198 | "1,2", 199 | "1,3", 200 | "1,4", 201 | "1,5", 202 | "1,6", 203 | "1,7", 204 | "1,8", 205 | "1,9", 206 | "1,10", 207 | "1,11", 208 | "1,12", 209 | {"c": "#aaaaaa", "w": 1.5}, 210 | "1,13" 211 | ], 212 | [ 213 | {"w": 1.75}, 214 | "2,0", 215 | {"c": "#cccccc"}, 216 | "2,1", 217 | "2,2", 218 | "2,3", 219 | "2,4", 220 | "2,5", 221 | "2,6", 222 | "2,7", 223 | "2,8", 224 | "2,9", 225 | "2,10", 226 | "2,11", 227 | {"c": "#888888", "w": 2.25}, 228 | "2,12" 229 | ], 230 | [ 231 | {"c": "#aaaaaa", "w": 2.25}, 232 | "3,0", 233 | {"c": "#cccccc"}, 234 | "3,2", 235 | "3,3", 236 | "3,4", 237 | "3,5", 238 | "3,6", 239 | "3,7", 240 | "3,8", 241 | "3,9", 242 | "3,10", 243 | "3,11", 244 | {"c": "#aaaaaa", "w": 1.75}, 245 | "3,12", 246 | "3,13" 247 | ], 248 | [ 249 | {"c": "#cccccc", "w": 1.5, "d": true}, 250 | "\n\n\n0,0", 251 | {"c": "#aaaaaa"}, 252 | "4,1\n\n\n0,0", 253 | {"w": 1.5}, 254 | "4,2\n\n\n0,0", 255 | {"c": "#cccccc", "w": 7}, 256 | "4,7\n\n\n0,0", 257 | {"c": "#aaaaaa", "w": 1.5}, 258 | "4,11\n\n\n0,0", 259 | "4,12\n\n\n0,0", 260 | {"c": "#cccccc", "w": 1.5, "d": true}, 261 | "\n\n\n0,0" 262 | ], 263 | [ 264 | {"y": 0.25, "c": "#aaaaaa", "w": 1.5}, 265 | "4,0\n\n\n0,1", 266 | "4,1\n\n\n0,1", 267 | {"w": 1.5}, 268 | "4,2\n\n\n0,1", 269 | {"c": "#cccccc", "w": 7}, 270 | "4,7\n\n\n0,1", 271 | {"c": "#aaaaaa", "w": 1.5}, 272 | "4,11\n\n\n0,1", 273 | "4,12\n\n\n0,1", 274 | {"w": 1.5}, 275 | "4,13\n\n\n0,1" 276 | ] 277 | ] 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /test/keyboard-definition-validator.v2.test.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import {test, expect} from 'vitest'; 3 | import validateKeyboardDefinitionV2 from '../src/validated-types/keyboard-definition-v2.validator'; 4 | 5 | test('valid definition passes', async () => { 6 | const validDefinitionJson = await fs.promises.readFile( 7 | './test/data/v2_valid_definition.json', 8 | 'utf-8' 9 | ); 10 | const validDefinition = JSON.parse(validDefinitionJson); 11 | 12 | expect(() => validateKeyboardDefinitionV2(validDefinition)).not.toThrow(); 13 | }); 14 | 15 | test('invalid definition fails', async () => { 16 | const invalidDefinitionJson = await fs.promises.readFile( 17 | './test/data/v2_invalid_definition.json', 18 | 'utf-8' 19 | ); 20 | const invalidDefinition = JSON.parse(invalidDefinitionJson); 21 | 22 | expect(() => validateKeyboardDefinitionV2(invalidDefinition)).toThrow(); 23 | }); 24 | 25 | test('v3 definition fails', async () => { 26 | const v3DefinitionJson = await fs.promises.readFile( 27 | './test/data/v3_valid_definition.json', 28 | 'utf-8' 29 | ); 30 | const v3Definition = JSON.parse(v3DefinitionJson); 31 | 32 | expect(() => validateKeyboardDefinitionV2(v3Definition)).toThrow(); 33 | }); 34 | -------------------------------------------------------------------------------- /test/keyboard-definition-validator.v3.test.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import {test, expect} from 'vitest'; 3 | import validateKeyboardDefinitionV3 from '../src/validated-types/keyboard-definition-v3.validator'; 4 | 5 | test('valid definition passes', async () => { 6 | const validDefinitionJson = await fs.promises.readFile( 7 | './test/data/v3_valid_definition.json', 8 | 'utf-8' 9 | ); 10 | const validDefinition = JSON.parse(validDefinitionJson); 11 | 12 | expect(() => validateKeyboardDefinitionV3(validDefinition)).not.toThrow(); 13 | }); 14 | 15 | test('invalid definition fails', async () => { 16 | const invalidDefinitionJson = await fs.promises.readFile( 17 | './test/data/v3_invalid_definition.json', 18 | 'utf-8' 19 | ); 20 | const invalidDefinition = JSON.parse(invalidDefinitionJson); 21 | 22 | expect(() => validateKeyboardDefinitionV3(invalidDefinition)).toThrow(); 23 | }); 24 | 25 | test('v2 definition fails', async () => { 26 | const v2DefinitionJson = await fs.promises.readFile( 27 | './test/data/v2_valid_definition.json', 28 | 'utf-8' 29 | ); 30 | const v2Definition = JSON.parse(v2DefinitionJson); 31 | 32 | expect(() => validateKeyboardDefinitionV3(v2Definition)).toThrow(); 33 | }); 34 | -------------------------------------------------------------------------------- /test/transform.v2.test.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import {test, expect} from 'vitest'; 3 | import {keyboardDefinitionV2ToVIADefinitionV2} from '../src'; 4 | import validateViaDefinitionV2 from '../src/validated-types/via-definition-v2.validator'; 5 | 6 | test('transform KeyboardDefinition to VIADefinition', async () => { 7 | const validDefinitionJson = await fs.promises.readFile( 8 | './test/data/v2_valid_definition.json', 9 | 'utf-8' 10 | ); 11 | const validDefinition = JSON.parse(validDefinitionJson); 12 | const viaDefinition = keyboardDefinitionV2ToVIADefinitionV2(validDefinition); 13 | 14 | expect(() => validateViaDefinitionV2(viaDefinition)).not.toThrow(); 15 | }); 16 | 17 | test('invalid label map fails', async () => { 18 | const invalidLabelMapJson = await fs.promises.readFile( 19 | './test/data/v2_invalid_label_map.json', 20 | 'utf-8' 21 | ); 22 | const invalidLabelMap = JSON.parse(invalidLabelMapJson); 23 | 24 | expect(() => 25 | keyboardDefinitionV2ToVIADefinitionV2(invalidLabelMap) 26 | ).toThrowErrorMatchingInlineSnapshot('"\'Row,col\' pairs must be placed in the top-left legend in the KLE keymap provided in the definition."'); 27 | }); 28 | 29 | test('can transform simple encoder', async () => { 30 | const simpleEncoderJson = await fs.promises.readFile( 31 | './test/data/v2_has_simple_encoder.json', 32 | 'utf-8' 33 | ); 34 | const simpleEncoder = JSON.parse(simpleEncoderJson); 35 | 36 | expect(() => 37 | keyboardDefinitionV2ToVIADefinitionV2(simpleEncoder) 38 | ).not.toThrow(); 39 | }); 40 | -------------------------------------------------------------------------------- /test/transform.v3.test.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import {test, expect} from 'vitest'; 3 | import { 4 | getVendorProductId, 5 | keyboardDefinitionV3ToVIADefinitionV3, 6 | } from '../src'; 7 | import validateViaDefinitionV3 from '../src/validated-types/via-definition-v3.validator'; 8 | 9 | test('transform KeyboardDefinition to VIADefinition', async () => { 10 | const validDefinitionJson = await fs.promises.readFile( 11 | './test/data/v3_valid_definition.json', 12 | 'utf-8' 13 | ); 14 | const validDefinition = JSON.parse(validDefinitionJson); 15 | const viaDefinition = keyboardDefinitionV3ToVIADefinitionV3(validDefinition); 16 | 17 | expect(() => validateViaDefinitionV3(viaDefinition)).not.toThrow(); 18 | }); 19 | 20 | test('invalid label map fails', async () => { 21 | const invalidLabelMapJson = await fs.promises.readFile( 22 | './test/data/v3_invalid_label_map.json', 23 | 'utf-8' 24 | ); 25 | const invalidLabelMap = JSON.parse(invalidLabelMapJson); 26 | 27 | expect(() => 28 | keyboardDefinitionV3ToVIADefinitionV3(invalidLabelMap) 29 | ).toThrowErrorMatchingInlineSnapshot( 30 | '"\'Row,col\' pairs must be placed in the top-left legend in the KLE keymap provided in the definition."' 31 | ); 32 | }); 33 | 34 | test('can transform simple encoder', async () => { 35 | const simpleEncoderJson = await fs.promises.readFile( 36 | './test/data/v3_has_simple_encoder.json', 37 | 'utf-8' 38 | ); 39 | const simpleEncoder = JSON.parse(simpleEncoderJson); 40 | 41 | expect(() => 42 | keyboardDefinitionV3ToVIADefinitionV3(simpleEncoder) 43 | ).not.toThrow(); 44 | }); 45 | 46 | test(`Vendor ID of '0xFEED' should fail`, () => { 47 | expect(() => getVendorProductId({productId: '0x1234', vendorId: '0xFEED'})) 48 | .toThrowErrorMatchingInlineSnapshot(` 49 | "'0xFEED' is not a valid vendorId." 50 | `); 51 | expect(() => getVendorProductId({productId: '0x1234', vendorId: '0xfeed'})) 52 | .toThrowErrorMatchingInlineSnapshot(` 53 | "'0xFEED' is not a valid vendorId." 54 | `); 55 | expect(() => 56 | getVendorProductId({productId: '0xFEED', vendorId: '0x1234'}) 57 | ).not.toThrow(); 58 | }); 59 | 60 | test('invalid common menu fails', async () => { 61 | const invalidCommonMenuDefinitionJson = await fs.promises.readFile( 62 | './test/data/v3_invalid_common_menu.json', 63 | 'utf-8' 64 | ); 65 | 66 | const invalidCommonMenuDefinition = JSON.parse( 67 | invalidCommonMenuDefinitionJson 68 | ); 69 | 70 | expect(() => 71 | keyboardDefinitionV3ToVIADefinitionV3(invalidCommonMenuDefinition) 72 | ).toThrowErrorMatchingInlineSnapshot('"Common menus not for found for: wt_rgb_backlight"'); 73 | }); 74 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["src/**/*"], 3 | "compilerOptions": { 4 | /* Basic Options */ 5 | // "incremental": true, /* Enable incremental compilation */ 6 | "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, 7 | "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, 8 | "lib": [ 9 | "esnext", 10 | "es2019", 11 | "es2019.array", 12 | "WebWorker" 13 | ] /* Specify library files to be included in the compilation. */, 14 | // "allowJs": true, /* Allow javascript files to be compiled. */ 15 | // "checkJs": true, /* Report errors in .js files. */ 16 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 17 | "declaration": true /* Generates corresponding '.d.ts' file. */, 18 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 19 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 20 | // "outFile": "./", /* Concatenate and emit output to single file. */ 21 | "outDir": "./dist/" /* Redirect output structure to the directory. */, 22 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 23 | // "composite": true, /* Enable project compilation */ 24 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 25 | // "removeComments": true, /* Do not emit comments to output. */ 26 | // "noEmit": true, /* Do not emit outputs. */ 27 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 28 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 29 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 30 | 31 | /* Strict Type-Checking Options */ 32 | "strict": true /* Enable all strict type-checking options. */, 33 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 34 | // "strictNullChecks": true, /* Enable strict null checks. */ 35 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 36 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 37 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 38 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 39 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 40 | 41 | /* Additional Checks */ 42 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 43 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 44 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 45 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 46 | 47 | /* Module Resolution Options */ 48 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 49 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 50 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 51 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 52 | // "typeRoots": [], /* List of folders to include type definitions from. */ 53 | // "types": [], /* Type declaration files to be included in compilation. */ 54 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 55 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, 56 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 57 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 58 | 59 | /* Source Map Options */ 60 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 61 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 62 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 63 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 64 | 65 | /* Experimental Options */ 66 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 67 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 68 | 69 | /* Advanced Options */ 70 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ 71 | } 72 | } 73 | --------------------------------------------------------------------------------