Skip to content

Commit d3d8ba6

Browse files
committed
Enhance README.md with KDL patching guidelines and documentation
1 parent e33c346 commit d3d8ba6

1 file changed

Lines changed: 62 additions & 1 deletion

File tree

inputfiles/README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,67 @@ Some files in this directory are generated. Please do not edit them.
44
This specifically includes:
55

66
* `idl/*`
7-
* `mdn/*`
87

98
Feel free to send a pull request with changes to any other files.
9+
Note It is recommended to add your patch use KDL format, continue reading to find out more.
10+
11+
## Documentation for `patches/` KDL Folder
12+
13+
The `patches/` directory only contains `.kdl` files that specify modifications ("patches") to the default Web IDL or related specifications, using the [KDL format](https://kdl.dev/).
14+
These modifications are integrated into the build system (see [`src/build/patches.ts`](../src/build/patches.ts) for implementation details).
15+
16+
### Purpose
17+
18+
- Fix errors or omissions in upstream IDL data.
19+
- Add or override or remove interfaces, mixins, and enums.
20+
- Apply project-specific features or changes.
21+
22+
### Editing Policy
23+
24+
It is **recommended** to document and comment your patch files and their intent.
25+
This helps keep the integration clear and maintainable.
26+
27+
### Patch File Naming Policy
28+
29+
When naming a KDL file, use the exact name of the main interface or dictionary as it appears in the official Web IDL specification. For reference and consistency, we recommend verifying names using [https://respec.org/xref/](https://respec.org/xref/).
30+
31+
32+
### Structure & Parsing
33+
34+
- All `.kdl` files in this folder are read and parsed at build time.
35+
- Their structure typically mirrors major Web IDL concepts:
36+
- `enum`
37+
- `interface`
38+
- `interface-mixin`
39+
- `dictionary`
40+
- Members like `event`, `property`, and `method`.
41+
42+
#### Example Patch File (`patches/tuoach-events.kdl`)
43+
```kdl
44+
interface-mixin GlobalEventHandlers {
45+
// Touch event handlers are intentionally hidden in non-mobile web browsers.
46+
// See w3c.github.io/touch-events#dfn-expose-legacy-touch-event-apis.
47+
property ontouchcancel optional=#true
48+
property ontouchend optional=#true
49+
property ontouchmove optional=#true
50+
property ontouchstart optional=#true
51+
}
52+
53+
```
54+
55+
### How It Works
56+
57+
The builder (see `src/build/patches.ts`):
58+
59+
- Locates all KDL files in the `patches/` directory.
60+
- Parses and type-checks them.
61+
- Merges their contents and applies structural transformations over the main IDL dataset.
62+
63+
See the source or comments in `patches.ts` for precise KDL syntax and advanced features.
64+
65+
### Notes
66+
67+
- You can split patches into multiple `.kdl` files if desired.
68+
- All the data in the json and jsonc files will be eventually transformed to KDL, so if possible submit patches to KDL.
69+
- When in doubt, consult `/src/build/patches.ts` for details on supported KDL structure and merging logic.
70+
- If there is a feature that is missing from the KDL parser, feel free to implement it yourself or ping @bashamega to help implement that feature in [this issue](https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/2053), or just add it to the jsonc files.

0 commit comments

Comments
 (0)