@gtkx/codegen 1.0.0-rc.3 → 1.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/README.md +4 -5
  2. package/dist/analysis/descriptor-render.d.ts +1 -3
  3. package/dist/analysis/descriptor-render.d.ts.map +1 -1
  4. package/dist/analysis/descriptor-render.js +14 -37
  5. package/dist/analysis/descriptor-render.js.map +1 -1
  6. package/dist/analysis/descriptor.d.ts +6 -6
  7. package/dist/analysis/descriptor.d.ts.map +1 -1
  8. package/dist/analysis/descriptor.js +7 -7
  9. package/dist/analysis/descriptor.js.map +1 -1
  10. package/dist/analysis/param-structure.d.ts +2 -2
  11. package/dist/analysis/param-structure.d.ts.map +1 -1
  12. package/dist/analysis/param-structure.js +5 -7
  13. package/dist/analysis/param-structure.js.map +1 -1
  14. package/dist/analysis/ts-type.d.ts +1 -1
  15. package/dist/analysis/ts-type.d.ts.map +1 -1
  16. package/dist/analysis/ts-type.js +3 -5
  17. package/dist/analysis/ts-type.js.map +1 -1
  18. package/dist/compile.d.ts.map +1 -1
  19. package/dist/compile.js +2 -1
  20. package/dist/compile.js.map +1 -1
  21. package/dist/docs/api-reference.d.ts +77 -1
  22. package/dist/docs/api-reference.d.ts.map +1 -1
  23. package/dist/docs/api-reference.js +62 -0
  24. package/dist/docs/api-reference.js.map +1 -1
  25. package/dist/docs/pipeline.d.ts +4 -4
  26. package/dist/docs/pipeline.d.ts.map +1 -1
  27. package/dist/docs/pipeline.js +4 -4
  28. package/dist/docs/pipeline.js.map +1 -1
  29. package/dist/docs/render.js +6 -6
  30. package/dist/docs/render.js.map +1 -1
  31. package/dist/docs/symbol-page.d.ts +5 -0
  32. package/dist/docs/symbol-page.d.ts.map +1 -1
  33. package/dist/docs/symbol-page.js +2 -2
  34. package/dist/docs/symbol-page.js.map +1 -1
  35. package/dist/fingerprint.d.ts +2 -5
  36. package/dist/fingerprint.d.ts.map +1 -1
  37. package/dist/fingerprint.js +6 -8
  38. package/dist/fingerprint.js.map +1 -1
  39. package/dist/gi.d.ts +3 -11
  40. package/dist/gi.d.ts.map +1 -1
  41. package/dist/gi.js +0 -7
  42. package/dist/gi.js.map +1 -1
  43. package/dist/gir/field.d.ts +0 -1
  44. package/dist/gir/field.d.ts.map +1 -1
  45. package/dist/gir/field.js +0 -3
  46. package/dist/gir/field.js.map +1 -1
  47. package/dist/gir/gir-path.d.ts +7 -0
  48. package/dist/gir/gir-path.d.ts.map +1 -1
  49. package/dist/gir/gir-path.js +7 -0
  50. package/dist/gir/gir-path.js.map +1 -1
  51. package/dist/gir/libraries.d.ts +13 -0
  52. package/dist/gir/libraries.d.ts.map +1 -1
  53. package/dist/gir/libraries.js +12 -0
  54. package/dist/gir/libraries.js.map +1 -1
  55. package/dist/gir/parameter.d.ts.map +1 -1
  56. package/dist/gir/parameter.js +0 -4
  57. package/dist/gir/parameter.js.map +1 -1
  58. package/dist/gir/size.d.ts.map +1 -1
  59. package/dist/gir/size.js +0 -3
  60. package/dist/gir/size.js.map +1 -1
  61. package/dist/gir/type-id.d.ts +1 -1
  62. package/dist/gir/type-id.d.ts.map +1 -1
  63. package/dist/gir/type-id.js +1 -3
  64. package/dist/gir/type-id.js.map +1 -1
  65. package/dist/gir/type-ref.js +1 -1
  66. package/dist/gir/type-ref.js.map +1 -1
  67. package/dist/index.d.ts +18 -6
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +12 -3
  70. package/dist/index.js.map +1 -1
  71. package/dist/internal.d.ts +3 -0
  72. package/dist/internal.d.ts.map +1 -0
  73. package/dist/internal.js +3 -0
  74. package/dist/internal.js.map +1 -0
  75. package/dist/jsx.d.ts +7 -12
  76. package/dist/jsx.d.ts.map +1 -1
  77. package/dist/jsx.js +18 -19
  78. package/dist/jsx.js.map +1 -1
  79. package/dist/khronos/args.d.ts.map +1 -1
  80. package/dist/khronos/args.js +1 -1
  81. package/dist/khronos/args.js.map +1 -1
  82. package/dist/khronos/pipeline.js +1 -1
  83. package/dist/khronos/pipeline.js.map +1 -1
  84. package/dist/khronos/plan.d.ts +2 -2
  85. package/dist/khronos/plan.d.ts.map +1 -1
  86. package/dist/khronos/plan.js +6 -6
  87. package/dist/khronos/plan.js.map +1 -1
  88. package/dist/react/element-config.d.ts +17 -11
  89. package/dist/react/element-config.d.ts.map +1 -1
  90. package/dist/react/element-config.js +22 -15
  91. package/dist/react/element-config.js.map +1 -1
  92. package/dist/runner.d.ts +35 -17
  93. package/dist/runner.d.ts.map +1 -1
  94. package/dist/runner.js +19 -20
  95. package/dist/runner.js.map +1 -1
  96. package/dist/store/compile-store.d.ts +1 -2
  97. package/dist/store/compile-store.d.ts.map +1 -1
  98. package/dist/store/compile-store.js +2 -2
  99. package/dist/store/compile-store.js.map +1 -1
  100. package/dist/store/gi/callables.js +4 -4
  101. package/dist/store/gi/callables.js.map +1 -1
  102. package/dist/store/gi/constant.d.ts.map +1 -1
  103. package/dist/store/gi/constant.js +0 -2
  104. package/dist/store/gi/constant.js.map +1 -1
  105. package/dist/store/gi/function.d.ts.map +1 -1
  106. package/dist/store/gi/function.js +1 -5
  107. package/dist/store/gi/function.js.map +1 -1
  108. package/dist/store/gi/method.d.ts.map +1 -1
  109. package/dist/store/gi/method.js +25 -23
  110. package/dist/store/gi/method.js.map +1 -1
  111. package/dist/store/gi/property-accessor.d.ts +1 -1
  112. package/dist/store/gi/property-accessor.d.ts.map +1 -1
  113. package/dist/store/gi/property-accessor.js +5 -7
  114. package/dist/store/gi/property-accessor.js.map +1 -1
  115. package/dist/store/gi/record-field-accessor.d.ts +1 -1
  116. package/dist/store/gi/record-field-accessor.d.ts.map +1 -1
  117. package/dist/store/gi/record-field-accessor.js +3 -9
  118. package/dist/store/gi/record-field-accessor.js.map +1 -1
  119. package/dist/store/gi/record-layout.d.ts.map +1 -1
  120. package/dist/store/gi/record-layout.js +0 -4
  121. package/dist/store/gi/record-layout.js.map +1 -1
  122. package/dist/store/gi/return-wrap.d.ts +1 -1
  123. package/dist/store/gi/return-wrap.d.ts.map +1 -1
  124. package/dist/store/gi/return-wrap.js +4 -4
  125. package/dist/store/gi/return-wrap.js.map +1 -1
  126. package/dist/store/gi/signal.d.ts.map +1 -1
  127. package/dist/store/gi/signal.js +13 -16
  128. package/dist/store/gi/signal.js.map +1 -1
  129. package/dist/store/gi/value-marshalable.d.ts +0 -8
  130. package/dist/store/gi/value-marshalable.d.ts.map +1 -1
  131. package/dist/store/gi/value-marshalable.js +0 -9
  132. package/dist/store/gi/value-marshalable.js.map +1 -1
  133. package/dist/store/gi-store.d.ts +2 -3
  134. package/dist/store/gi-store.d.ts.map +1 -1
  135. package/dist/store/gi-store.js.map +1 -1
  136. package/dist/store/jsx/element-components.d.ts +0 -2
  137. package/dist/store/jsx/element-components.d.ts.map +1 -1
  138. package/dist/store/jsx/element-components.js +0 -4
  139. package/dist/store/jsx/element-components.js.map +1 -1
  140. package/dist/store/jsx/element-prop-imports.d.ts +2 -3
  141. package/dist/store/jsx/element-prop-imports.d.ts.map +1 -1
  142. package/dist/store/jsx/element-prop-imports.js +0 -2
  143. package/dist/store/jsx/element-prop-imports.js.map +1 -1
  144. package/dist/store/jsx/element-prop-types.d.ts +0 -1
  145. package/dist/store/jsx/element-prop-types.d.ts.map +1 -1
  146. package/dist/store/jsx/element-prop-types.js +0 -1
  147. package/dist/store/jsx/element-prop-types.js.map +1 -1
  148. package/dist/store/jsx/generated-elements.d.ts +29 -0
  149. package/dist/store/jsx/generated-elements.d.ts.map +1 -0
  150. package/dist/store/jsx/generated-elements.js +30 -0
  151. package/dist/store/jsx/generated-elements.js.map +1 -0
  152. package/dist/store/jsx/jsx.js +6 -6
  153. package/dist/store/jsx/jsx.js.map +1 -1
  154. package/dist/store/jsx/metadata.js +7 -7
  155. package/dist/store/jsx/metadata.js.map +1 -1
  156. package/dist/store/jsx/omitted-props.d.ts +2 -4
  157. package/dist/store/jsx/omitted-props.d.ts.map +1 -1
  158. package/dist/store/jsx/omitted-props.js +2 -4
  159. package/dist/store/jsx/omitted-props.js.map +1 -1
  160. package/dist/store/jsx/pipeline.d.ts +3 -1
  161. package/dist/store/jsx/pipeline.d.ts.map +1 -1
  162. package/dist/store/jsx/pipeline.js +3 -2
  163. package/dist/store/jsx/pipeline.js.map +1 -1
  164. package/dist/store/jsx/props.js +2 -2
  165. package/dist/store/jsx/props.js.map +1 -1
  166. package/dist/store/jsx-store.d.ts +2 -3
  167. package/dist/store/jsx-store.d.ts.map +1 -1
  168. package/dist/store/jsx-store.js +3 -3
  169. package/dist/store/jsx-store.js.map +1 -1
  170. package/dist/store/resolve-store.d.ts +28 -0
  171. package/dist/store/resolve-store.d.ts.map +1 -0
  172. package/dist/store/resolve-store.js +65 -0
  173. package/dist/store/resolve-store.js.map +1 -0
  174. package/dist/store/store-fs.d.ts +5 -1
  175. package/dist/store/store-fs.d.ts.map +1 -1
  176. package/dist/store/store-fs.js +6 -4
  177. package/dist/store/store-fs.js.map +1 -1
  178. package/overrides/gobject/object.ts.ejs +8 -8
  179. package/package.json +6 -10
  180. package/src/analysis/descriptor-render.ts +20 -45
  181. package/src/analysis/descriptor.ts +13 -13
  182. package/src/analysis/param-structure.ts +8 -10
  183. package/src/analysis/ts-type.ts +4 -6
  184. package/src/compile.ts +2 -1
  185. package/src/docs/api-reference.ts +127 -4
  186. package/src/docs/pipeline.ts +8 -8
  187. package/src/docs/render.ts +7 -7
  188. package/src/docs/symbol-page.ts +7 -2
  189. package/src/fingerprint.ts +8 -13
  190. package/src/gi.ts +4 -11
  191. package/src/gir/field.ts +0 -4
  192. package/src/gir/gir-path.ts +7 -0
  193. package/src/gir/libraries.ts +13 -0
  194. package/src/gir/parameter.ts +0 -4
  195. package/src/gir/size.ts +0 -3
  196. package/src/gir/type-id.ts +2 -4
  197. package/src/gir/type-ref.ts +1 -1
  198. package/src/index.ts +18 -16
  199. package/src/internal.ts +2 -0
  200. package/src/jsx.ts +26 -26
  201. package/src/khronos/args.ts +1 -1
  202. package/src/khronos/pipeline.ts +1 -1
  203. package/src/khronos/plan.ts +8 -8
  204. package/src/react/element-config.ts +22 -19
  205. package/src/runner.ts +57 -39
  206. package/src/store/compile-store.ts +3 -4
  207. package/src/store/gi/callables.ts +5 -5
  208. package/src/store/gi/constant.ts +0 -2
  209. package/src/store/gi/function.ts +1 -5
  210. package/src/store/gi/method.ts +30 -28
  211. package/src/store/gi/property-accessor.ts +6 -8
  212. package/src/store/gi/record-field-accessor.ts +4 -10
  213. package/src/store/gi/record-layout.ts +0 -4
  214. package/src/store/gi/return-wrap.ts +5 -5
  215. package/src/store/gi/signal.ts +17 -17
  216. package/src/store/gi/value-marshalable.ts +0 -9
  217. package/src/store/gi-store.ts +2 -4
  218. package/src/store/jsx/element-components.ts +0 -6
  219. package/src/store/jsx/element-prop-imports.ts +7 -4
  220. package/src/store/jsx/element-prop-types.ts +0 -1
  221. package/src/store/jsx/generated-elements.ts +60 -0
  222. package/src/store/jsx/jsx.ts +7 -7
  223. package/src/store/jsx/metadata.ts +8 -8
  224. package/src/store/jsx/omitted-props.ts +2 -4
  225. package/src/store/jsx/pipeline.ts +5 -3
  226. package/src/store/jsx/props.ts +2 -2
  227. package/src/store/jsx-store.ts +5 -7
  228. package/src/store/resolve-store.ts +100 -0
  229. package/src/store/store-fs.ts +12 -5
@@ -40,8 +40,6 @@ const closureAndDestroyIndices = (fn) => {
40
40
  }
41
41
  return indices;
42
42
  };
43
- // The emitted argument list is the instance parameter followed by every parameter `planParameter`
44
- // keeps, so a GIR index only lines up with an emitted index when nothing before it was dropped.
45
43
  const emittedArgIndices = (fn, instanceOffset) => {
46
44
  const closureIndices = closureAndDestroyIndices(fn);
47
45
  const map = new Map();
@@ -123,7 +121,7 @@ const foldOutParamShape = (primary, outTypes) => {
123
121
  return `[${outTypes.join(", ")}]`;
124
122
  };
125
123
  const isHandlerOutParameter = (options) => {
126
- const { library, parameter, includeCallerAllocated } = options;
124
+ const { library, parameter, shouldIncludeCallerAllocated } = options;
127
125
  if (parameter.isVarargs) {
128
126
  return false;
129
127
  }
@@ -133,7 +131,7 @@ const isHandlerOutParameter = (options) => {
133
131
  if (isCellInout(library, parameter)) {
134
132
  return true;
135
133
  }
136
- return includeCallerAllocated && isCallerAllocatedOut(parameter);
134
+ return shouldIncludeCallerAllocated && isCallerAllocatedOut(parameter);
137
135
  };
138
136
  const scalarResultType = (primary, isOptOut) => {
139
137
  if (primary === undefined) {
@@ -142,15 +140,15 @@ const scalarResultType = (primary, isOptOut) => {
142
140
  return isOptOut ? `${primary} | undefined` : primary;
143
141
  };
144
142
  const renderHandlerResultType = (options) => {
145
- const { library, signal, renderType, includeCallerAllocated, optOut } = options;
143
+ const { library, signal, renderType, shouldIncludeCallerAllocated, isOptOut } = options;
146
144
  const primary = shouldOmitPrimaryReturn(library, signal.returnValue)
147
145
  ? undefined
148
146
  : renderType(signal.returnValue.type, signal.returnValue.nullable);
149
147
  const outTypes = signal.parameters
150
- .filter((parameter) => isHandlerOutParameter({ library, parameter, includeCallerAllocated }))
148
+ .filter((parameter) => isHandlerOutParameter({ library, parameter, shouldIncludeCallerAllocated }))
151
149
  .map((parameter) => renderType(parameter.type, parameter.nullable));
152
150
  if (outTypes.length === 0) {
153
- return scalarResultType(primary, optOut);
151
+ return scalarResultType(primary, isOptOut);
154
152
  }
155
153
  return foldOutParamShape(primary, outTypes);
156
154
  };
@@ -1 +1 @@
1
- {"version":3,"file":"param-structure.js","sourceRoot":"","sources":["../../src/analysis/param-structure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD,OAAO,EAAuC,oBAAoB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChH,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAe9E,MAAM,gBAAgB,GAAG,CAAC,OAKzB,EAAW,EAAE;IACV,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,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O,MAAM,CAAC;IAClB,CAAC;IAED,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,OAA6B,EAAU,EAAE;IACtE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEhF,MAAM,OAAO,GAAG,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC;QAChE,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAEvE,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU;SAC7B,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,qBAAqB,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC,CAAC;SAC5F,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IAExE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,OAAO,EACH,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,EAC7B,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,EACjB,uBAAuB,GAC1B,CAAC","sourcesContent":["import { toCamelIdentifier } from \"@gtkx/utils\";\nimport type { GirFunction } from \"../gir/function.js\";\nimport type { Library } from \"../gir/library.js\";\nimport type { TypeId } from \"../gir/type-id.js\";\nimport { type GirCallable, type GirParameter, isCallerAllocatedOut, isOutParameter } from \"../gir/parameter.js\";\nimport { isCellInout, shouldOmitPrimaryReturn } from \"./descriptor-render.js\";\n\ntype InputParameter = {\n parameter: GirParameter;\n index: number;\n};\n\ntype HandlerResultOptions = {\n library: Library;\n signal: GirCallable;\n renderType: (ref: TypeId | undefined, isNullable: boolean) => string;\n includeCallerAllocated: boolean;\n optOut: boolean;\n};\n\nconst isInputParameter = (options: {\n parameter: GirParameter;\n index: number;\n lengthIndices: Set<number>;\n closureIndices: Set<number>;\n}): boolean => {\n const { parameter, index, lengthIndices, closureIndices } = options;\n\n if (parameter.isVarargs) {\n return false;\n }\n\n if (isOutParameter(parameter)) {\n return false;\n }\n\n if (isCallerAllocatedOut(parameter)) {\n return false;\n }\n\n if (lengthIndices.has(index)) {\n return false;\n }\n\n return !closureIndices.has(index);\n};\n\nconst inputParameters = (library: Library, fn: GirFunction): InputParameter[] => {\n const lengthIndices = arrayLengthIndices(library, fn);\n const closureIndices = closureAndDestroyIndices(fn);\n const result: InputParameter[] = [];\n\n for (const [index, parameter] of fn.parameters.entries()) {\n if (isInputParameter({ parameter, index, lengthIndices, closureIndices })) {\n result.push({ parameter, index });\n }\n }\n\n return result;\n};\n\nconst closureAndDestroyIndices = (fn: GirFunction): Set<number> => {\n const indices: Set<number> = new Set();\n\n for (const parameter of fn.parameters) {\n if (parameter.closureIndex !== undefined) {\n indices.add(parameter.closureIndex);\n }\n\n if (parameter.destroyIndex !== undefined) {\n indices.add(parameter.destroyIndex);\n }\n }\n\n return indices;\n};\n\n// The emitted argument list is the instance parameter followed by every parameter `planParameter`\n// keeps, so a GIR index only lines up with an emitted index when nothing before it was dropped.\nconst emittedArgIndices = (fn: GirFunction, instanceOffset: number): Map<number, number> => {\n const closureIndices = closureAndDestroyIndices(fn);\n const map: Map<number, number> = new Map();\n let emitted = instanceOffset;\n\n for (const [index, parameter] of fn.parameters.entries()) {\n if (parameter.isVarargs || closureIndices.has(index)) {\n continue;\n }\n\n map.set(index, emitted);\n emitted += 1;\n }\n\n return map;\n};\n\nconst arrayLengthIndices = (library: Library, fn: GirFunction): Set<number> => {\n const map = arrayLengthSources(library, fn);\n\n return new Set(map.keys());\n};\n\nconst carrayLengthIndex = (library: Library, ref: TypeId | undefined): number | undefined => {\n const type = ref === undefined ? undefined : library.typeFor(ref);\n\n if (type?.kind !== \"carray\") {\n return undefined;\n }\n\n return type.lengthParameterIndex;\n};\n\nconst arrayLengthSources = (library: Library, fn: GirFunction): Map<number, number> => {\n const map: Map<number, number> = new Map();\n\n for (const [index, parameter] of fn.parameters.entries()) {\n const lengthIndex = carrayLengthIndex(library, parameter.type);\n\n if (lengthIndex !== undefined) {\n map.set(lengthIndex, index);\n }\n }\n\n return map;\n};\n\nconst hasCallerAllocatedArrayLength = (library: Library, fn: GirFunction): boolean => {\n for (const arrayIndex of arrayLengthSources(library, fn).values()) {\n const array = fn.parameters[arrayIndex];\n\n if (array !== undefined && isCallerAllocatedOut(array)) {\n return true;\n }\n }\n\n return false;\n};\n\nconst returnArrayLengthIndices = (library: Library, fn: GirFunction): Set<number> => {\n const returnType = fn.returnValue.type === undefined ? undefined : library.typeFor(fn.returnValue.type);\n\n if (returnType?.kind !== \"carray\") {\n return new Set();\n }\n\n const lengthIndex = returnType.lengthParameterIndex;\n\n if (lengthIndex === undefined) {\n return new Set();\n }\n\n return new Set([lengthIndex]);\n};\n\nconst foldedLengthIndices = (library: Library, fn: GirFunction): Set<number> => {\n const indices: Set<number> = new Set(arrayLengthSources(library, fn).keys());\n\n for (const index of returnArrayLengthIndices(library, fn)) {\n indices.add(index);\n }\n\n return indices;\n};\n\nconst parameterIdentifier = (parameter: GirParameter, index: number): string => {\n if (parameter.name.length === 0) {\n return `arg${String(index)}`;\n }\n\n return toCamelIdentifier(parameter.name);\n};\n\nconst renderHandlerParameters = (\n parameters: GirParameter[],\n renderType: (ref: TypeId | undefined, isNullable: boolean) => string,\n shouldExclude: (parameter: GirParameter) => boolean = () => false,\n): string[] =>\n parameters\n .filter((parameter) => !parameter.isVarargs && !isOutParameter(parameter) && !shouldExclude(parameter))\n .map(\n (parameter, index) =>\n `${parameterIdentifier(parameter, index)}: ${renderType(parameter.type, parameter.nullable)}`,\n );\n\nconst foldOutParamShape = (primary: string | undefined, outTypes: string[]): string => {\n if (primary !== undefined) {\n return `[${primary}, ${outTypes.join(\", \")}]`;\n }\n\n const [single, ...rest] = outTypes;\n\n if (single !== undefined && rest.length === 0) {\n return single;\n }\n\n return `[${outTypes.join(\", \")}]`;\n};\n\nconst isHandlerOutParameter = (options: {\n library: Library;\n parameter: GirParameter;\n includeCallerAllocated: boolean;\n}): boolean => {\n const { library, parameter, includeCallerAllocated } = options;\n\n if (parameter.isVarargs) {\n return false;\n }\n\n if (isOutParameter(parameter)) {\n return true;\n }\n\n if (isCellInout(library, parameter)) {\n return true;\n }\n\n return includeCallerAllocated && isCallerAllocatedOut(parameter);\n};\n\nconst scalarResultType = (primary: string | undefined, isOptOut: boolean): string => {\n if (primary === undefined) {\n return \"void\";\n }\n\n return isOptOut ? `${primary} | undefined` : primary;\n};\n\nconst renderHandlerResultType = (options: HandlerResultOptions): string => {\n const { library, signal, renderType, includeCallerAllocated, optOut } = options;\n\n const primary = shouldOmitPrimaryReturn(library, signal.returnValue)\n ? undefined\n : renderType(signal.returnValue.type, signal.returnValue.nullable);\n\n const outTypes = signal.parameters\n .filter((parameter) => isHandlerOutParameter({ library, parameter, includeCallerAllocated }))\n .map((parameter) => renderType(parameter.type, parameter.nullable));\n\n if (outTypes.length === 0) {\n return scalarResultType(primary, optOut);\n }\n\n return foldOutParamShape(primary, outTypes);\n};\n\nexport {\n emittedArgIndices,\n inputParameters,\n closureAndDestroyIndices,\n arrayLengthSources,\n hasCallerAllocatedArrayLength,\n foldedLengthIndices,\n parameterIdentifier,\n renderHandlerParameters,\n foldOutParamShape,\n renderHandlerResultType,\n};\n"]}
1
+ {"version":3,"file":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AAC;IAED,OAAO,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,OAAO,EACH,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,EAC7B,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,EACjB,uBAAuB,GAC1B,CAAC","sourcesContent":["import { toCamelIdentifier } from \"@gtkx/utils\";\nimport type { GirFunction } from \"../gir/function.js\";\nimport type { Library } from \"../gir/library.js\";\nimport type { TypeId } from \"../gir/type-id.js\";\nimport { type GirCallable, type GirParameter, isCallerAllocatedOut, isOutParameter } from \"../gir/parameter.js\";\nimport { isCellInout, shouldOmitPrimaryReturn } from \"./descriptor-render.js\";\n\ntype InputParameter = {\n parameter: GirParameter;\n index: number;\n};\n\ntype HandlerResultOptions = {\n library: Library;\n signal: GirCallable;\n renderType: (ref: TypeId | undefined, isNullable: boolean) => string;\n shouldIncludeCallerAllocated: boolean;\n isOptOut: boolean;\n};\n\nconst isInputParameter = (options: {\n parameter: GirParameter;\n index: number;\n lengthIndices: Set<number>;\n closureIndices: Set<number>;\n}): boolean => {\n const { parameter, index, lengthIndices, closureIndices } = options;\n\n if (parameter.isVarargs) {\n return false;\n }\n\n if (isOutParameter(parameter)) {\n return false;\n }\n\n if (isCallerAllocatedOut(parameter)) {\n return false;\n }\n\n if (lengthIndices.has(index)) {\n return false;\n }\n\n return !closureIndices.has(index);\n};\n\nconst inputParameters = (library: Library, fn: GirFunction): InputParameter[] => {\n const lengthIndices = arrayLengthIndices(library, fn);\n const closureIndices = closureAndDestroyIndices(fn);\n const result: InputParameter[] = [];\n\n for (const [index, parameter] of fn.parameters.entries()) {\n if (isInputParameter({ parameter, index, lengthIndices, closureIndices })) {\n result.push({ parameter, index });\n }\n }\n\n return result;\n};\n\nconst closureAndDestroyIndices = (fn: GirFunction): Set<number> => {\n const indices: Set<number> = new Set();\n\n for (const parameter of fn.parameters) {\n if (parameter.closureIndex !== undefined) {\n indices.add(parameter.closureIndex);\n }\n\n if (parameter.destroyIndex !== undefined) {\n indices.add(parameter.destroyIndex);\n }\n }\n\n return indices;\n};\n\nconst emittedArgIndices = (fn: GirFunction, instanceOffset: number): Map<number, number> => {\n const closureIndices = closureAndDestroyIndices(fn);\n const map: Map<number, number> = new Map();\n let emitted = instanceOffset;\n\n for (const [index, parameter] of fn.parameters.entries()) {\n if (parameter.isVarargs || closureIndices.has(index)) {\n continue;\n }\n\n map.set(index, emitted);\n emitted += 1;\n }\n\n return map;\n};\n\nconst arrayLengthIndices = (library: Library, fn: GirFunction): Set<number> => {\n const map = arrayLengthSources(library, fn);\n\n return new Set(map.keys());\n};\n\nconst carrayLengthIndex = (library: Library, ref: TypeId | undefined): number | undefined => {\n const type = ref === undefined ? undefined : library.typeFor(ref);\n\n if (type?.kind !== \"carray\") {\n return undefined;\n }\n\n return type.lengthParameterIndex;\n};\n\nconst arrayLengthSources = (library: Library, fn: GirFunction): Map<number, number> => {\n const map: Map<number, number> = new Map();\n\n for (const [index, parameter] of fn.parameters.entries()) {\n const lengthIndex = carrayLengthIndex(library, parameter.type);\n\n if (lengthIndex !== undefined) {\n map.set(lengthIndex, index);\n }\n }\n\n return map;\n};\n\nconst hasCallerAllocatedArrayLength = (library: Library, fn: GirFunction): boolean => {\n for (const arrayIndex of arrayLengthSources(library, fn).values()) {\n const array = fn.parameters[arrayIndex];\n\n if (array !== undefined && isCallerAllocatedOut(array)) {\n return true;\n }\n }\n\n return false;\n};\n\nconst returnArrayLengthIndices = (library: Library, fn: GirFunction): Set<number> => {\n const returnType = fn.returnValue.type === undefined ? undefined : library.typeFor(fn.returnValue.type);\n\n if (returnType?.kind !== \"carray\") {\n return new Set();\n }\n\n const lengthIndex = returnType.lengthParameterIndex;\n\n if (lengthIndex === undefined) {\n return new Set();\n }\n\n return new Set([lengthIndex]);\n};\n\nconst foldedLengthIndices = (library: Library, fn: GirFunction): Set<number> => {\n const indices: Set<number> = new Set(arrayLengthSources(library, fn).keys());\n\n for (const index of returnArrayLengthIndices(library, fn)) {\n indices.add(index);\n }\n\n return indices;\n};\n\nconst parameterIdentifier = (parameter: GirParameter, index: number): string => {\n if (parameter.name.length === 0) {\n return `arg${String(index)}`;\n }\n\n return toCamelIdentifier(parameter.name);\n};\n\nconst renderHandlerParameters = (\n parameters: GirParameter[],\n renderType: (ref: TypeId | undefined, isNullable: boolean) => string,\n shouldExclude: (parameter: GirParameter) => boolean = () => false,\n): string[] =>\n parameters\n .filter((parameter) => !parameter.isVarargs && !isOutParameter(parameter) && !shouldExclude(parameter))\n .map(\n (parameter, index) =>\n `${parameterIdentifier(parameter, index)}: ${renderType(parameter.type, parameter.nullable)}`,\n );\n\nconst foldOutParamShape = (primary: string | undefined, outTypes: string[]): string => {\n if (primary !== undefined) {\n return `[${primary}, ${outTypes.join(\", \")}]`;\n }\n\n const [single, ...rest] = outTypes;\n\n if (single !== undefined && rest.length === 0) {\n return single;\n }\n\n return `[${outTypes.join(\", \")}]`;\n};\n\nconst isHandlerOutParameter = (options: {\n library: Library;\n parameter: GirParameter;\n shouldIncludeCallerAllocated: boolean;\n}): boolean => {\n const { library, parameter, shouldIncludeCallerAllocated } = options;\n\n if (parameter.isVarargs) {\n return false;\n }\n\n if (isOutParameter(parameter)) {\n return true;\n }\n\n if (isCellInout(library, parameter)) {\n return true;\n }\n\n return shouldIncludeCallerAllocated && isCallerAllocatedOut(parameter);\n};\n\nconst scalarResultType = (primary: string | undefined, isOptOut: boolean): string => {\n if (primary === undefined) {\n return \"void\";\n }\n\n return isOptOut ? `${primary} | undefined` : primary;\n};\n\nconst renderHandlerResultType = (options: HandlerResultOptions): string => {\n const { library, signal, renderType, shouldIncludeCallerAllocated, isOptOut } = options;\n\n const primary = shouldOmitPrimaryReturn(library, signal.returnValue)\n ? undefined\n : renderType(signal.returnValue.type, signal.returnValue.nullable);\n\n const outTypes = signal.parameters\n .filter((parameter) => isHandlerOutParameter({ library, parameter, shouldIncludeCallerAllocated }))\n .map((parameter) => renderType(parameter.type, parameter.nullable));\n\n if (outTypes.length === 0) {\n return scalarResultType(primary, isOptOut);\n }\n\n return foldOutParamShape(primary, outTypes);\n};\n\nexport {\n emittedArgIndices,\n inputParameters,\n closureAndDestroyIndices,\n arrayLengthSources,\n hasCallerAllocatedArrayLength,\n foldedLengthIndices,\n parameterIdentifier,\n renderHandlerParameters,\n foldOutParamShape,\n renderHandlerResultType,\n};\n"]}
@@ -9,7 +9,7 @@ type ReferenceName = {
9
9
  type TsTypeTarget = {
10
10
  containerStyle: "map" | "record";
11
11
  callbackType: string;
12
- byteArrayAsNumber: boolean;
12
+ shouldRenderByteArrayAsNumber: boolean;
13
13
  renderNamed: (resolved: GirType | undefined, name: ReferenceName) => string;
14
14
  renderGtype: () => string;
15
15
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ts-type.d.ts","sourceRoot":"","sources":["../../src/analysis/ts-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAc,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAKH,KAAK,MAAM,EACd,MAAM,mBAAmB,CAAC;AAG3B,KAAK,aAAa,GAAG;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,cAAc,EAAE,KAAK,GAAG,QAAQ,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,EAAE,aAAa,KAAK,MAAM,CAAC;IAC5E,WAAW,EAAE,MAAM,MAAM,CAAC;CAC7B,CAAC;AA4BF,QAAA,MAAM,cAAc,GAAI,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,GAAI,SAAS,aAAa,EAAE,KAAK,MAAM,GAAG,SAAS,EAAE,oBAAkB,KAAG,MAI3F,CAAC;AAEF,QAAA,MAAM,gBAAgB,GAClB,SAAS,OAAO,EAChB,gBAAgB,CAAC,IAAI,EAAE,aAAa,KAAK,MAAM,EAC/C,aAAa,MAAM,MAAM,KAC1B,YAkBF,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,KAAK,YAAY,EAAE,CAAC"}
@@ -58,10 +58,8 @@ const renderContainerType = (library, target, type) => {
58
58
  }
59
59
  return renderSequenceType(library, target, type);
60
60
  };
61
- // An array whose length nothing states decodes as the bare pointer it is, so its TypeScript type has
62
- // to say so too rather than promising elements nothing can count.
63
61
  const renderSequenceType = (library, target, type) => {
64
- if (type.kind === "list" && type.flavor === "gbytearray" && target.byteArrayAsNumber) {
62
+ if (type.kind === "list" && type.flavor === "gbytearray" && target.shouldRenderByteArrayAsNumber) {
65
63
  return "number[]";
66
64
  }
67
65
  if (type.kind === "carray" && hasUnknownArrayLength(type)) {
@@ -78,7 +76,7 @@ const renderNamedType = (target, resolved, name) => {
78
76
  const moduleTarget = (context) => ({
79
77
  containerStyle: "map",
80
78
  callbackType: "((...args: any[]) => any)",
81
- byteArrayAsNumber: true,
79
+ shouldRenderByteArrayAsNumber: true,
82
80
  renderNamed: (_resolved, name) => context.qualify(name.namespaceName, name.typeName),
83
81
  renderGtype: () => gtypeTsType(context),
84
82
  });
@@ -90,7 +88,7 @@ const recordTypeTarget = (library, renderNamedRef, renderGtype) => {
90
88
  const target = {
91
89
  containerStyle: "record",
92
90
  callbackType: "((...args: unknown[]) => unknown)",
93
- byteArrayAsNumber: false,
91
+ shouldRenderByteArrayAsNumber: false,
94
92
  renderNamed: (resolved, name) => {
95
93
  if (resolved?.kind === "alias") {
96
94
  return resolved.value.target === undefined
@@ -1 +1 @@
1
- {"version":3,"file":"ts-type.js","sourceRoot":"","sources":["../../src/analysis/ts-type.ts"],"names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gB,EAAqB,CAAC","sourcesContent":["import type { Library } from \"../gir/library.js\";\nimport type { EntityType, GirType } from \"../gir/type.js\";\nimport type { ModuleContext } from \"../writer/context.js\";\nimport { PRIMITIVE_TS_TYPE } from \"../gir/primitives.js\";\nimport {\n type CArrayType,\n type HashTableType,\n hasUnknownArrayLength,\n type ListType,\n type TypeId,\n} from \"../gir/type-id.js\";\nimport { gtypeTsType } from \"../store/gi/gtype-binding.js\";\n\ntype ReferenceName = {\n namespaceName: string;\n typeName: string;\n};\n\ntype TsTypeTarget = {\n containerStyle: \"map\" | \"record\";\n callbackType: string;\n byteArrayAsNumber: boolean;\n renderNamed: (resolved: GirType | undefined, name: ReferenceName) => string;\n renderGtype: () => string;\n};\n\nconst willEmitEntity = (type: EntityType): boolean => {\n switch (type.kind) {\n case \"callback\": {\n return type.value.introspectable && type.value.name.length > 0;\n }\n case \"record\": {\n return type.value.introspectable && type.value.name.length > 0;\n }\n case \"alias\":\n case \"class\":\n case \"enum\":\n case \"interface\": {\n return true;\n }\n }\n};\n\nconst renderPrimitiveType = (target: TsTypeTarget, type: Extract<GirType, { kind: \"primitive\" }>): string =>\n type.category === \"gtype\" ? target.renderGtype() : PRIMITIVE_TS_TYPE[type.category];\n\nconst renderEntityType = (\n target: TsTypeTarget,\n type: EntityType,\n name: ReferenceName | undefined,\n): string => renderNamedType(target, type, willEmitEntity(type) ? name : undefined);\n\nconst renderBaseType = (library: Library, target: TsTypeTarget, ref: TypeId | undefined): string => {\n if (ref === undefined) {\n return \"void\";\n }\n\n const type = library.typeFor(ref);\n const name = library.nameFor(ref);\n\n if (type === undefined) {\n return renderNamedType(target, undefined, name);\n }\n\n switch (type.kind) {\n case \"primitive\": {\n return renderPrimitiveType(target, type);\n }\n case \"varargs\": {\n return \"unknown[]\";\n }\n case \"callback\":\n case \"class\":\n case \"interface\":\n case \"record\":\n case \"enum\":\n case \"alias\": {\n return renderEntityType(target, type, name);\n }\n case \"carray\":\n case \"list\":\n case \"hashtable\": {\n return renderContainerType(library, target, type);\n }\n }\n};\n\nconst renderContainerType = (\n library: Library,\n target: TsTypeTarget,\n type: CArrayType | ListType | HashTableType,\n): string => {\n if (type.kind === \"hashtable\") {\n const key = renderBaseType(library, target, type.key);\n const value = renderBaseType(library, target, type.value);\n\n return target.containerStyle === \"record\" ? `Record<${key}, ${value}>` : `Map<${key}, ${value}>`;\n }\n\n return renderSequenceType(library, target, type);\n};\n\n// An array whose length nothing states decodes as the bare pointer it is, so its TypeScript type has\n// to say so too rather than promising elements nothing can count.\nconst renderSequenceType = (library: Library, target: TsTypeTarget, type: CArrayType | ListType): string => {\n if (type.kind === \"list\" && type.flavor === \"gbytearray\" && target.byteArrayAsNumber) {\n return \"number[]\";\n }\n\n if (type.kind === \"carray\" && hasUnknownArrayLength(type)) {\n return \"number\";\n }\n\n return `${renderBaseType(library, target, type.element)}[]`;\n};\n\nconst renderNamedType = (\n target: TsTypeTarget,\n resolved: GirType | undefined,\n name: ReferenceName | undefined,\n): string => {\n if (name === undefined || name.typeName.length === 0) {\n return resolved?.kind === \"callback\" ? target.callbackType : \"unknown\";\n }\n\n return target.renderNamed(resolved, name);\n};\n\nconst moduleTarget = (context: ModuleContext): TsTypeTarget => ({\n containerStyle: \"map\",\n callbackType: \"((...args: any[]) => any)\",\n byteArrayAsNumber: true,\n renderNamed: (_resolved, name) => context.qualify(name.namespaceName, name.typeName),\n renderGtype: () => gtypeTsType(context),\n});\n\nconst renderTsType = (context: ModuleContext, ref: TypeId | undefined, isNullable = false): string => {\n const base = renderBaseType(context.library, moduleTarget(context), ref);\n\n return isNullable ? `${base} | null` : base;\n};\n\nconst recordTypeTarget = (\n library: Library,\n renderNamedRef: (name: ReferenceName) => string,\n renderGtype: () => string,\n): TsTypeTarget => {\n const target: TsTypeTarget = {\n containerStyle: \"record\",\n callbackType: \"((...args: unknown[]) => unknown)\",\n byteArrayAsNumber: false,\n renderNamed: (resolved, name) => {\n if (resolved?.kind === \"alias\") {\n return resolved.value.target === undefined\n ? \"number\"\n : renderBaseType(library, target, resolved.value.target);\n }\n\n return renderNamedRef(name);\n },\n renderGtype,\n };\n\n return target;\n};\n\nexport { renderBaseType, renderTsType, recordTypeTarget, type TsTypeTarget };\n"]}
1
+ {"version":3,"file":"ts-type.js","sourceRoot":"","sources":["../../src/analysis/ts-type.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAGH,qBAAqB,GAGxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAe3D,MAAM,cAAc,GAAG,CAAC,IAAgB,EAAW,EAAE;IACjD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAChB,KAAK,UAAU,CAAC,CAAC,CAAC;YACd,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACnE,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACZ,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACnE,CAAC;QACD,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,MAAM,CAAC;QACZ,KAAK,WAAW,CAAC,CAAC,CAAC;YACf,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAAC,MAAoB,EAAE,IAA6C,EAAU,EAAE,CACxG,IAAI,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAExF,MAAM,gBAAgB,GAAG,CACrB,MAAoB,EACpB,IAAgB,EAChB,IAA+B,EACzB,EAAE,C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ACjE,CAAC;YAED,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QACD,WAAW;KACd,CAAC;IAEF,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAqB,CAAC","sourcesContent":["import type { Library } from \"../gir/library.js\";\nimport type { EntityType, GirType } from \"../gir/type.js\";\nimport type { ModuleContext } from \"../writer/context.js\";\nimport { PRIMITIVE_TS_TYPE } from \"../gir/primitives.js\";\nimport {\n type CArrayType,\n type HashTableType,\n hasUnknownArrayLength,\n type ListType,\n type TypeId,\n} from \"../gir/type-id.js\";\nimport { gtypeTsType } from \"../store/gi/gtype-binding.js\";\n\ntype ReferenceName = {\n namespaceName: string;\n typeName: string;\n};\n\ntype TsTypeTarget = {\n containerStyle: \"map\" | \"record\";\n callbackType: string;\n shouldRenderByteArrayAsNumber: boolean;\n renderNamed: (resolved: GirType | undefined, name: ReferenceName) => string;\n renderGtype: () => string;\n};\n\nconst willEmitEntity = (type: EntityType): boolean => {\n switch (type.kind) {\n case \"callback\": {\n return type.value.introspectable && type.value.name.length > 0;\n }\n case \"record\": {\n return type.value.introspectable && type.value.name.length > 0;\n }\n case \"alias\":\n case \"class\":\n case \"enum\":\n case \"interface\": {\n return true;\n }\n }\n};\n\nconst renderPrimitiveType = (target: TsTypeTarget, type: Extract<GirType, { kind: \"primitive\" }>): string =>\n type.category === \"gtype\" ? target.renderGtype() : PRIMITIVE_TS_TYPE[type.category];\n\nconst renderEntityType = (\n target: TsTypeTarget,\n type: EntityType,\n name: ReferenceName | undefined,\n): string => renderNamedType(target, type, willEmitEntity(type) ? name : undefined);\n\nconst renderBaseType = (library: Library, target: TsTypeTarget, ref: TypeId | undefined): string => {\n if (ref === undefined) {\n return \"void\";\n }\n\n const type = library.typeFor(ref);\n const name = library.nameFor(ref);\n\n if (type === undefined) {\n return renderNamedType(target, undefined, name);\n }\n\n switch (type.kind) {\n case \"primitive\": {\n return renderPrimitiveType(target, type);\n }\n case \"varargs\": {\n return \"unknown[]\";\n }\n case \"callback\":\n case \"class\":\n case \"interface\":\n case \"record\":\n case \"enum\":\n case \"alias\": {\n return renderEntityType(target, type, name);\n }\n case \"carray\":\n case \"list\":\n case \"hashtable\": {\n return renderContainerType(library, target, type);\n }\n }\n};\n\nconst renderContainerType = (\n library: Library,\n target: TsTypeTarget,\n type: CArrayType | ListType | HashTableType,\n): string => {\n if (type.kind === \"hashtable\") {\n const key = renderBaseType(library, target, type.key);\n const value = renderBaseType(library, target, type.value);\n\n return target.containerStyle === \"record\" ? `Record<${key}, ${value}>` : `Map<${key}, ${value}>`;\n }\n\n return renderSequenceType(library, target, type);\n};\n\nconst renderSequenceType = (library: Library, target: TsTypeTarget, type: CArrayType | ListType): string => {\n if (type.kind === \"list\" && type.flavor === \"gbytearray\" && target.shouldRenderByteArrayAsNumber) {\n return \"number[]\";\n }\n\n if (type.kind === \"carray\" && hasUnknownArrayLength(type)) {\n return \"number\";\n }\n\n return `${renderBaseType(library, target, type.element)}[]`;\n};\n\nconst renderNamedType = (\n target: TsTypeTarget,\n resolved: GirType | undefined,\n name: ReferenceName | undefined,\n): string => {\n if (name === undefined || name.typeName.length === 0) {\n return resolved?.kind === \"callback\" ? target.callbackType : \"unknown\";\n }\n\n return target.renderNamed(resolved, name);\n};\n\nconst moduleTarget = (context: ModuleContext): TsTypeTarget => ({\n containerStyle: \"map\",\n callbackType: \"((...args: any[]) => any)\",\n shouldRenderByteArrayAsNumber: true,\n renderNamed: (_resolved, name) => context.qualify(name.namespaceName, name.typeName),\n renderGtype: () => gtypeTsType(context),\n});\n\nconst renderTsType = (context: ModuleContext, ref: TypeId | undefined, isNullable = false): string => {\n const base = renderBaseType(context.library, moduleTarget(context), ref);\n\n return isNullable ? `${base} | null` : base;\n};\n\nconst recordTypeTarget = (\n library: Library,\n renderNamedRef: (name: ReferenceName) => string,\n renderGtype: () => string,\n): TsTypeTarget => {\n const target: TsTypeTarget = {\n containerStyle: \"record\",\n callbackType: \"((...args: unknown[]) => unknown)\",\n shouldRenderByteArrayAsNumber: false,\n renderNamed: (resolved, name) => {\n if (resolved?.kind === \"alias\") {\n return resolved.value.target === undefined\n ? \"number\"\n : renderBaseType(library, target, resolved.value.target);\n }\n\n return renderNamedRef(name);\n },\n renderGtype,\n };\n\n return target;\n};\n\nexport { renderBaseType, renderTsType, recordTypeTarget, type TsTypeTarget };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAKA,KAAK,YAAY,GAAG;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AA8HF,QAAA,MAAM,cAAc,GAAI,QAAQ,oBAAoB,KAAG,IAYtD,CAAC;AAEF,QAAA,MAAM,YAAY,GAAI,QAAQ;IAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,KAAG,IAqB/F,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAKA,KAAK,YAAY,GAAG;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AA+HF,QAAA,MAAM,cAAc,GAAI,QAAQ,oBAAoB,KAAG,IAYtD,CAAC;AAEF,QAAA,MAAM,YAAY,GAAI,QAAQ;IAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,KAAG,IAqB/F,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,oBAAoB,EAAE,CAAC"}
package/dist/compile.js CHANGED
@@ -16,8 +16,10 @@ const BASE_COMPILER_OPTIONS = {
16
16
  noImplicitReturns: true,
17
17
  noFallthroughCasesInSwitch: true,
18
18
  allowUnreachableCode: false,
19
+ allowImportingTsExtensions: true,
19
20
  forceConsistentCasingInFileNames: true,
20
21
  resolveJsonModule: true,
22
+ rewriteRelativeImportExtensions: true,
21
23
  skipLibCheck: true,
22
24
  types: ["node"],
23
25
  };
@@ -31,7 +33,6 @@ const FORMAT_HOST = {
31
33
  getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
32
34
  getNewLine: () => "\n",
33
35
  };
34
- /** `@gtkx/codegen`'s own `node_modules`, which has `@types/node` plus the `@gtkx/*` deps the store typecheck needs. */
35
36
  const codegenModules = () => {
36
37
  const sourceDir = dirname(fileURLToPath(import.meta.url));
37
38
  return join(dirname(sourceDir), "node_modules");
@@ -1 +1 @@
1
- {"version":3,"file":"compile.js","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjG,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAA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C,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;IAEhE,IAAI,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YACnD,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC;QAED,cAAc,CAAC;YACX,UAAU;YACV,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;YAC1D,eAAe,EAAE,aAAa;YAC9B,KAAK,EAAE,MAAM,CAAC,KAAK;SACtB,CAAC,CAAC;IACP,CAAC;YAAS,CAAC;QACP,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;AACL,CAAC,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAgD,CAAC","sourcesContent":["import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, relative } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport ts from \"typescript\";\n\ntype SourceModule = {\n fileName: string;\n source: string;\n};\n\ntype CompileProjectParams = {\n projectDir: string;\n fileNames: string[];\n compilerOptions: Record<string, unknown>;\n label: string;\n};\n\nconst BASE_COMPILER_OPTIONS = {\n module: \"esnext\",\n moduleResolution: \"bundler\",\n target: \"esnext\",\n lib: [\"esnext\"],\n jsx: \"react-jsx\",\n jsxImportSource: \"react\",\n customConditions: [\"source\"],\n strict: true,\n exactOptionalPropertyTypes: true,\n noUncheckedIndexedAccess: true,\n noImplicitReturns: true,\n noFallthroughCasesInSwitch: true,\n allowUnreachableCode: false,\n forceConsistentCasingInFileNames: true,\n resolveJsonModule: true,\n skipLibCheck: true,\n types: [\"node\"],\n};\n\nconst CHECK_OPTIONS = {\n declaration: true,\n isolatedDeclarations: true,\n noEmit: true,\n};\n\nconst FORMAT_HOST: ts.FormatDiagnosticsHost = {\n getCanonicalFileName: (fileName) => fileName,\n getCurrentDirectory: () => ts.sys.getCurrentDirectory(),\n getNewLine: () => \"\\n\",\n};\n\n/** `@gtkx/codegen`'s own `node_modules`, which has `@types/node` plus the `@gtkx/*` deps the store typecheck needs. */\nconst codegenModules = (): string => {\n const sourceDir = dirname(fileURLToPath(import.meta.url));\n\n return join(dirname(sourceDir), \"node_modules\");\n};\n\nconst linkToolingModules = (projectDir: string): (() => void) => {\n const link = join(projectDir, \"node_modules\");\n\n if (existsSync(link)) {\n return (): void => undefined;\n }\n\n symlinkSync(codegenModules(), link, \"junction\");\n\n return () => {\n rmSync(link, { force: true });\n };\n};\n\nconst isProjectFile = (rel: string): boolean =>\n !rel.startsWith(\"..\") && !isAbsolute(rel) && !rel.split(/[/\\\\]/).includes(\"node_modules\");\n\nconst projectDiagnosticLine = (diagnostic: ts.Diagnostic, projectDir: string): string | undefined => {\n const { file, start } = diagnostic;\n\n if (file === undefined || start === undefined) {\n return undefined;\n }\n\n const filePath = relative(projectDir, file.fileName);\n\n if (!isProjectFile(filePath)) {\n return undefined;\n }\n\n const { line, character } = file.getLineAndCharacterOfPosition(start);\n const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, \"\\n\");\n\n return `${filePath}:${String(line + 1)}:${String(character + 1)} - ${message} (TS${String(diagnostic.code)})`;\n};\n\nconst projectDiagnosticLines = (diagnostics: ts.Diagnostic[], projectDir: string): string[] => {\n const lines: string[] = [];\n\n for (const diagnostic of diagnostics) {\n const line = projectDiagnosticLine(diagnostic, projectDir);\n\n if (line !== undefined) {\n lines.push(line);\n }\n }\n\n return lines;\n};\n\nconst diagnosticError = (label: string, projectDir: string, diagnostics: ts.Diagnostic[]): Error => {\n const lines = projectDiagnosticLines(diagnostics, projectDir);\n\n if (lines.length > 0) {\n return new Error(`Type checking ${label} found ${String(lines.length)} error(s):\\n${lines.join(\"\\n\")}`);\n }\n\n return new Error(`Type checking ${label} failed:\\n${ts.formatDiagnostics(diagnostics, FORMAT_HOST).trim()}`);\n};\n\nconst runProgram = (params: CompileProjectParams): ts.Diagnostic[] => {\n const parsed = ts.parseJsonConfigFileContent(\n {\n compilerOptions: { ...BASE_COMPILER_OPTIONS, ...params.compilerOptions },\n files: params.fileNames.map((name) => `./${name}`),\n },\n ts.sys,\n params.projectDir,\n );\n\n const program = ts.createProgram({\n rootNames: parsed.fileNames,\n options: parsed.options,\n configFileParsingDiagnostics: parsed.errors,\n });\n\n const diagnostics = ts.getPreEmitDiagnostics(program);\n\n if (diagnostics.length > 0) {\n return [...diagnostics];\n }\n\n return [...program.emit().diagnostics];\n};\n\nconst compileProject = (params: CompileProjectParams): void => {\n const unlinkToolingModules = linkToolingModules(params.projectDir);\n\n try {\n const diagnostics = runProgram(params);\n\n if (diagnostics.length > 0) {\n throw diagnosticError(params.label, params.projectDir, diagnostics);\n }\n } finally {\n unlinkToolingModules();\n }\n};\n\nconst checkModules = (params: { modules: SourceModule[]; resolveFrom: string; label: string }): void => {\n const checkRoot = join(params.resolveFrom, \"node_modules\");\n mkdirSync(checkRoot, { recursive: true });\n const projectDir = mkdtempSync(join(checkRoot, \".gtkx-check-\"));\n\n try {\n for (const module of params.modules) {\n const filePath = join(projectDir, module.fileName);\n mkdirSync(dirname(filePath), { recursive: true });\n writeFileSync(filePath, module.source);\n }\n\n compileProject({\n projectDir,\n fileNames: params.modules.map((module) => module.fileName),\n compilerOptions: CHECK_OPTIONS,\n label: params.label,\n });\n } finally {\n rmSync(projectDir, { recursive: true, force: true });\n }\n};\n\nexport { compileProject, checkModules, type SourceModule, type CompileProjectParams };\n"]}
1
+ {"version":3,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,CAAC;QACP,oBAAoB,EAAE,CAAC;IAC3B,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,MAAuE,EAAQ,EAAE;IACnG,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;IAC3D,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;IAEhE,IAAI,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YACnD,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC;QAED,cAAc,CAAC;YACX,UAAU;YACV,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;YAC1D,eAAe,EAAE,aAAa;YAC9B,KAAK,EAAE,MAAM,CAAC,KAAK;SACtB,CAAC,CAAC;IACP,CAAC;YAAS,CAAC;QACP,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;AACL,CAAC,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAgD,CAAC","sourcesContent":["import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, relative } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport ts from \"typescript\";\n\ntype SourceModule = {\n fileName: string;\n source: string;\n};\n\ntype CompileProjectParams = {\n projectDir: string;\n fileNames: string[];\n compilerOptions: Record<string, unknown>;\n label: string;\n};\n\nconst BASE_COMPILER_OPTIONS = {\n module: \"esnext\",\n moduleResolution: \"bundler\",\n target: \"esnext\",\n lib: [\"esnext\"],\n jsx: \"react-jsx\",\n jsxImportSource: \"react\",\n customConditions: [\"source\"],\n strict: true,\n exactOptionalPropertyTypes: true,\n noUncheckedIndexedAccess: true,\n noImplicitReturns: true,\n noFallthroughCasesInSwitch: true,\n allowUnreachableCode: false,\n allowImportingTsExtensions: true,\n forceConsistentCasingInFileNames: true,\n resolveJsonModule: true,\n rewriteRelativeImportExtensions: true,\n skipLibCheck: true,\n types: [\"node\"],\n};\n\nconst CHECK_OPTIONS = {\n declaration: true,\n isolatedDeclarations: true,\n noEmit: true,\n};\n\nconst FORMAT_HOST: ts.FormatDiagnosticsHost = {\n getCanonicalFileName: (fileName) => fileName,\n getCurrentDirectory: () => ts.sys.getCurrentDirectory(),\n getNewLine: () => \"\\n\",\n};\n\nconst codegenModules = (): string => {\n const sourceDir = dirname(fileURLToPath(import.meta.url));\n\n return join(dirname(sourceDir), \"node_modules\");\n};\n\nconst linkToolingModules = (projectDir: string): (() => void) => {\n const link = join(projectDir, \"node_modules\");\n\n if (existsSync(link)) {\n return (): void => undefined;\n }\n\n symlinkSync(codegenModules(), link, \"junction\");\n\n return () => {\n rmSync(link, { force: true });\n };\n};\n\nconst isProjectFile = (rel: string): boolean =>\n !rel.startsWith(\"..\") && !isAbsolute(rel) && !rel.split(/[/\\\\]/).includes(\"node_modules\");\n\nconst projectDiagnosticLine = (diagnostic: ts.Diagnostic, projectDir: string): string | undefined => {\n const { file, start } = diagnostic;\n\n if (file === undefined || start === undefined) {\n return undefined;\n }\n\n const filePath = relative(projectDir, file.fileName);\n\n if (!isProjectFile(filePath)) {\n return undefined;\n }\n\n const { line, character } = file.getLineAndCharacterOfPosition(start);\n const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, \"\\n\");\n\n return `${filePath}:${String(line + 1)}:${String(character + 1)} - ${message} (TS${String(diagnostic.code)})`;\n};\n\nconst projectDiagnosticLines = (diagnostics: ts.Diagnostic[], projectDir: string): string[] => {\n const lines: string[] = [];\n\n for (const diagnostic of diagnostics) {\n const line = projectDiagnosticLine(diagnostic, projectDir);\n\n if (line !== undefined) {\n lines.push(line);\n }\n }\n\n return lines;\n};\n\nconst diagnosticError = (label: string, projectDir: string, diagnostics: ts.Diagnostic[]): Error => {\n const lines = projectDiagnosticLines(diagnostics, projectDir);\n\n if (lines.length > 0) {\n return new Error(`Type checking ${label} found ${String(lines.length)} error(s):\\n${lines.join(\"\\n\")}`);\n }\n\n return new Error(`Type checking ${label} failed:\\n${ts.formatDiagnostics(diagnostics, FORMAT_HOST).trim()}`);\n};\n\nconst runProgram = (params: CompileProjectParams): ts.Diagnostic[] => {\n const parsed = ts.parseJsonConfigFileContent(\n {\n compilerOptions: { ...BASE_COMPILER_OPTIONS, ...params.compilerOptions },\n files: params.fileNames.map((name) => `./${name}`),\n },\n ts.sys,\n params.projectDir,\n );\n\n const program = ts.createProgram({\n rootNames: parsed.fileNames,\n options: parsed.options,\n configFileParsingDiagnostics: parsed.errors,\n });\n\n const diagnostics = ts.getPreEmitDiagnostics(program);\n\n if (diagnostics.length > 0) {\n return [...diagnostics];\n }\n\n return [...program.emit().diagnostics];\n};\n\nconst compileProject = (params: CompileProjectParams): void => {\n const unlinkToolingModules = linkToolingModules(params.projectDir);\n\n try {\n const diagnostics = runProgram(params);\n\n if (diagnostics.length > 0) {\n throw diagnosticError(params.label, params.projectDir, diagnostics);\n }\n } finally {\n unlinkToolingModules();\n }\n};\n\nconst checkModules = (params: { modules: SourceModule[]; resolveFrom: string; label: string }): void => {\n const checkRoot = join(params.resolveFrom, \"node_modules\");\n mkdirSync(checkRoot, { recursive: true });\n const projectDir = mkdtempSync(join(checkRoot, \".gtkx-check-\"));\n\n try {\n for (const module of params.modules) {\n const filePath = join(projectDir, module.fileName);\n mkdirSync(dirname(filePath), { recursive: true });\n writeFileSync(filePath, module.source);\n }\n\n compileProject({\n projectDir,\n fileNames: params.modules.map((module) => module.fileName),\n compilerOptions: CHECK_OPTIONS,\n label: params.label,\n });\n } finally {\n rmSync(projectDir, { recursive: true, force: true });\n }\n};\n\nexport { compileProject, checkModules, type SourceModule, type CompileProjectParams };\n"]}
@@ -1,39 +1,88 @@
1
+ import { type ElementProps } from "../store/jsx/element-prop-imports.js";
2
+ import { type OmittedProps } from "../store/jsx/omitted-props.js";
1
3
  import { type GiSymbolEntry } from "./symbol-page.js";
4
+ /** What to index and the element config the rendered pages reflect. */
2
5
  type ApiReferenceOptions = {
6
+ /** GIR library identifiers to load, such as `"Gtk-4.0"`; their dependencies are pulled in too. */
3
7
  libraries: string[];
8
+ /** Directories to search for `.gir` files. */
4
9
  girPath: string[];
10
+ /** Base props interfaces per element, as read by `readBuiltinElements`; without it pages miss them. */
11
+ props?: ElementProps;
12
+ /** GObject properties the project omits from generated props; without it pages show props that do not exist. */
13
+ omittedProps?: OmittedProps;
5
14
  };
15
+ /** Narrows an `ApiReference.symbols` enumeration. */
16
+ type ApiSymbolQuery = {
17
+ /** GIR namespace to keep, matched case-insensitively; every namespace when omitted. */
18
+ namespace?: string;
19
+ /** Symbol kinds to keep; every kind when omitted. */
20
+ kinds?: ApiSymbolKind[];
21
+ };
22
+ /** What an indexed symbol is: one of the GIR symbol kinds, or a JSX element. */
6
23
  type ApiSymbolKind = GiSymbolEntry["kind"] | "element";
24
+ /** An indexed symbol, without its reference page. */
7
25
  type ApiSymbol = {
26
+ /** GIR namespace declaring the symbol, such as `"Gtk"`. */
8
27
  namespace: string;
28
+ /** Name within the namespace, which for an element is its GLib type name. */
9
29
  name: string;
30
+ /** Kind the reference groups and filters the symbol by, `"element"` for a JSX tag. */
10
31
  kind: ApiSymbolKind;
32
+ /** First sentence of the symbol's GIR documentation, elided past 220 characters and empty when it has none. */
11
33
  summary: string;
12
34
  };
35
+ /** How much of one namespace the reference indexes. */
13
36
  type ApiNamespaceSummary = {
37
+ /** GIR namespace name, such as `"Gtk"`. */
14
38
  name: string;
39
+ /** The `@gtkx/gi` subpath the namespace's symbols are imported from. */
15
40
  importPath: string;
41
+ /** How many symbols other than JSX elements the namespace contributes. */
16
42
  symbols: number;
43
+ /** How many JSX elements the namespace contributes. */
17
44
  elements: number;
18
45
  };
46
+ /** What an `ApiReference.lookup` found: a rendered page, several candidates for the name, or nothing. */
19
47
  type ApiLookupResult = {
48
+ /** Discriminant selecting the variant. */
20
49
  outcome: "page";
50
+ /** Index entry for the symbol the query resolved to. */
21
51
  symbol: ApiSymbol;
52
+ /** The symbol's complete reference page, rendered as Markdown. */
22
53
  markdown: string;
23
54
  } | {
55
+ /** Discriminant selecting the variant. */
24
56
  outcome: "ambiguous";
57
+ /** Every symbol the name answers to, to be narrowed by namespace or kind. */
25
58
  candidates: ApiSymbol[];
26
59
  } | {
60
+ /** Discriminant selecting the variant. */
27
61
  outcome: "notFound";
28
62
  };
63
+ /** A fuzzy search over indexed symbol names. */
29
64
  type ApiSearchOptions = {
65
+ /** Text matched case-insensitively against each symbol's name and its qualified `Namespace.Name` form. */
30
66
  query: string;
67
+ /** GIR namespace to keep, matched case-insensitively; every namespace when omitted. */
31
68
  namespace?: string;
69
+ /** Symbol kinds to keep; every kind when omitted. */
32
70
  kinds?: ApiSymbolKind[];
71
+ /** Maximum number of results, 20 by default. */
33
72
  limit?: number;
34
73
  };
74
+ /** Every kind the reference indexes, in the order a namespace overview groups its symbols. */
35
75
  declare const API_SYMBOL_KINDS: ApiSymbolKind[];
76
+ /**
77
+ * Loads the GIR data for the given libraries and indexes every symbol and JSX element in it. The result is
78
+ * a read-only view: it generates no store and needs none, so a tool can explore the bindings a project would
79
+ * get without running codegen.
80
+ *
81
+ * @param options Which libraries to index, where to find them, and the project's element config.
82
+ * @returns The indexed reference.
83
+ */
36
84
  declare const loadApiReference: (options: ApiReferenceOptions) => ApiReference;
85
+ /** An index over the GIR data a project's bindings are generated from, queryable and renderable as Markdown. */
37
86
  declare class ApiReference {
38
87
  private library;
39
88
  private libraries;
@@ -43,7 +92,10 @@ declare class ApiReference {
43
92
  private byName;
44
93
  private byNamespace;
45
94
  private elementsByClass;
95
+ private props;
96
+ private omittedProps;
46
97
  constructor(options: ApiReferenceOptions);
98
+ private applyElementConfig;
47
99
  private add;
48
100
  private buildIndex;
49
101
  private indexNamespace;
@@ -54,14 +106,38 @@ declare class ApiReference {
54
106
  private findNamespace;
55
107
  private lookupCandidates;
56
108
  private scoreEntries;
109
+ /** Paths of the `.gir` files the index was built from, including the ones pulled in as dependencies. */
57
110
  get girFiles(): string[];
111
+ /**
112
+ * Resolves a name to a single symbol and renders its reference page. The name may be bare (`Button`) or
113
+ * qualified (`Gtk.Button`), and is matched case-insensitively; a name several symbols answer to is
114
+ * reported as ambiguous rather than picked between.
115
+ *
116
+ * @param kind Restricts the match to one kind, which is how a class and its JSX element are told apart.
117
+ */
58
118
  lookup(query: string, kind?: ApiSymbolKind): ApiLookupResult;
119
+ /** Every indexed symbol the query keeps, ordered by namespace (Gtk, then Adw, then alphabetically) and name. */
120
+ symbols(query?: ApiSymbolQuery): ApiSymbol[];
121
+ /**
122
+ * Symbols whose name matches the query, best first: an exact name beats a prefix, which beats a
123
+ * substring, and shorter names win ties. An empty query matches nothing.
124
+ */
59
125
  search(options: ApiSearchOptions): ApiSymbol[];
126
+ /** A summary of every indexed namespace, ordered Gtk, Adw, then alphabetically. */
60
127
  namespaces(): ApiNamespaceSummary[];
128
+ /**
129
+ * Sorted names of everything a namespace contributes, JSX elements included. The namespace is matched
130
+ * case-insensitively, and an unindexed one yields an empty array.
131
+ */
61
132
  symbolNames(namespaceName: string): string[];
133
+ /** Renders the reference's Markdown landing page: every namespace, its import path, and its totals. */
62
134
  overview(): string;
135
+ /**
136
+ * Renders one namespace's Markdown page: its import line and its symbol names grouped by kind. The
137
+ * namespace is matched case-insensitively, and an unindexed one yields undefined.
138
+ */
63
139
  namespaceOverview(name: string): string | undefined;
64
140
  }
65
141
  export type { ApiReference };
66
- export { API_SYMBOL_KINDS, loadApiReference, type ApiReferenceOptions, type ApiSymbolKind, type ApiSymbol, type ApiNamespaceSummary, type ApiLookupResult, type ApiSearchOptions, };
142
+ export { API_SYMBOL_KINDS, loadApiReference, type ApiReferenceOptions, type ApiSymbolKind, type ApiSymbol, type ApiNamespaceSummary, type ApiLookupResult, type ApiSearchOptions, type ApiSymbolQuery, };
67
143
  //# sourceMappingURL=api-reference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-reference.d.ts","sourceRoot":"","sources":["../../src/docs/api-reference.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,aAAa,EAA4C,MAAM,kBAAkB,CAAC;AAEhG,KAAK,mBAAmB,GAAG;IACvB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,KAAK,aAAa,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AAEvD,KAAK,SAAS,GAAG;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,eAAe,GACd;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,OAAO,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,GACjD;IAAE,OAAO,EAAE,UAAU,CAAA;CAAE,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;IAEzD,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,YAAY,CAAe;gBAEvB,OAAO,EAAE,mBAAmB;IASxC,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,GAAG;IAcX,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,YAAY;IAkBpB,wGAAwG;IACxG,IAAI,QAAQ,IAAI,MAAM,EAAE,CAEvB;IAED;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,eAAe;IAqB5D,gHAAgH;IAChH,OAAO,CAAC,KAAK,GAAE,cAAmB,GAAG,SAAS,EAAE;IAUhD;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,EAAE;IAe9C,mFAAmF;IACnF,UAAU,IAAI,mBAAmB,EAAE;IAWnC;;;OAGG;IACH,WAAW,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE;IAY5C,uGAAuG;IACvG,QAAQ,IAAI,MAAM;IA2BlB;;;OAGG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAqCtD;AAED,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACtB,CAAC"}
@@ -3,10 +3,13 @@ import { Library } from "../gir/library.js";
3
3
  import { namespaceDirectory } from "../gir/namespace.js";
4
4
  import { dedupeCallables, isEmittableCallable } from "../store/gi/callables.js";
5
5
  import { namespaceFunctionExportName } from "../store/gi/function.js";
6
+ import { setElementProps } from "../store/jsx/element-prop-imports.js";
6
7
  import { collectIntrinsicElementClasses } from "../store/jsx/intrinsic-elements.js";
8
+ import { setOmittedProps } from "../store/jsx/omitted-props.js";
7
9
  import { createElementPageContext, renderElementPage } from "./element-page.js";
8
10
  import { docsSignatureContext, firstSentence, namespaceOrder } from "./render.js";
9
11
  import { renderSymbolPage } from "./symbol-page.js";
12
+ /** Every kind the reference indexes, in the order a namespace overview groups its symbols. */
10
13
  const API_SYMBOL_KINDS = [
11
14
  "element",
12
15
  "class",
@@ -36,6 +39,24 @@ const compareNames = (a, b) => {
36
39
  }
37
40
  return a > b ? 1 : 0;
38
41
  };
42
+ const isQueriedEntry = (entry, namespaceFilter, kinds) => {
43
+ if (namespaceFilter !== undefined && entry.namespace.name.toLowerCase() !== namespaceFilter) {
44
+ return false;
45
+ }
46
+ return kinds === undefined || kinds.has(entry.kind);
47
+ };
48
+ const compareApiSymbols = (a, b) => {
49
+ const byNamespace = namespaceOrder(a.namespace).localeCompare(namespaceOrder(b.namespace));
50
+ return byNamespace === 0 ? a.name.localeCompare(b.name) : byNamespace;
51
+ };
52
+ /**
53
+ * Loads the GIR data for the given libraries and indexes every symbol and JSX element in it. The result is
54
+ * a read-only view: it generates no store and needs none, so a tool can explore the bindings a project would
55
+ * get without running codegen.
56
+ *
57
+ * @param options Which libraries to index, where to find them, and the project's element config.
58
+ * @returns The indexed reference.
59
+ */
39
60
  const loadApiReference = (options) => new ApiReference(options);
40
61
  const functionEntry = (namespace, docsContext, fn) => {
41
62
  if (!isEmittableCallable(docsContext, fn)) {
@@ -160,6 +181,7 @@ const searchScore = (entry, query) => {
160
181
  }
161
182
  return 0;
162
183
  };
184
+ /** An index over the GIR data a project's bindings are generated from, queryable and renderable as Markdown. */
163
185
  class ApiReference {
164
186
  library;
165
187
  libraries;
@@ -169,12 +191,20 @@ class ApiReference {
169
191
  byName = new Map();
170
192
  byNamespace = new Map();
171
193
  elementsByClass = new Map();
194
+ props;
195
+ omittedProps;
172
196
  constructor(options) {
173
197
  this.libraries = options.libraries;
198
+ this.props = options.props ?? {};
199
+ this.omittedProps = options.omittedProps ?? {};
174
200
  this.library = Library.load(options.libraries, options.girPath);
175
201
  this.elementContext = createElementPageContext(this.library, () => undefined);
176
202
  this.buildIndex();
177
203
  }
204
+ applyElementConfig() {
205
+ setElementProps(this.props);
206
+ setOmittedProps(this.omittedProps);
207
+ }
178
208
  add(entry) {
179
209
  this.entries.push(entry);
180
210
  const push = (map, key) => {
@@ -240,6 +270,7 @@ class ApiReference {
240
270
  }
241
271
  renderPage(entry) {
242
272
  if (entry.kind === "element") {
273
+ this.applyElementConfig();
243
274
  return renderElementPage(entry.element, this.elementContext);
244
275
  }
245
276
  return renderSymbolPage(entry, this.symbolPageOptions());
@@ -272,9 +303,17 @@ class ApiReference {
272
303
  }
273
304
  return scored;
274
305
  }
306
+ /** Paths of the `.gir` files the index was built from, including the ones pulled in as dependencies. */
275
307
  get girFiles() {
276
308
  return this.library.girFiles;
277
309
  }
310
+ /**
311
+ * Resolves a name to a single symbol and renders its reference page. The name may be bare (`Button`) or
312
+ * qualified (`Gtk.Button`), and is matched case-insensitively; a name several symbols answer to is
313
+ * reported as ambiguous rather than picked between.
314
+ *
315
+ * @param kind Restricts the match to one kind, which is how a class and its JSX element are told apart.
316
+ */
278
317
  lookup(query, kind) {
279
318
  const trimmed = query.trim();
280
319
  if (trimmed.length === 0) {
@@ -290,6 +329,19 @@ class ApiReference {
290
329
  }
291
330
  return { outcome: "page", symbol: this.toApiSymbol(entry), markdown: this.renderPage(entry) };
292
331
  }
332
+ /** Every indexed symbol the query keeps, ordered by namespace (Gtk, then Adw, then alphabetically) and name. */
333
+ symbols(query = {}) {
334
+ const namespaceFilter = query.namespace?.toLowerCase();
335
+ const kinds = query.kinds === undefined ? undefined : new Set(query.kinds);
336
+ return this.entries
337
+ .filter((entry) => isQueriedEntry(entry, namespaceFilter, kinds))
338
+ .map((entry) => this.toApiSymbol(entry))
339
+ .toSorted(compareApiSymbols);
340
+ }
341
+ /**
342
+ * Symbols whose name matches the query, best first: an exact name beats a prefix, which beats a
343
+ * substring, and shorter names win ties. An empty query matches nothing.
344
+ */
293
345
  search(options) {
294
346
  const query = options.query.trim().toLowerCase();
295
347
  if (query.length === 0) {
@@ -301,6 +353,7 @@ class ApiReference {
301
353
  scored.sort(compareScoredEntries);
302
354
  return scored.slice(0, limit).map((item) => this.toApiSymbol(item.entry));
303
355
  }
356
+ /** A summary of every indexed namespace, ordered Gtk, Adw, then alphabetically. */
304
357
  namespaces() {
305
358
  const summaries = [...this.byNamespace].map(([name, entries]) => ({
306
359
  name,
@@ -310,6 +363,10 @@ class ApiReference {
310
363
  }));
311
364
  return sortStringsBy(summaries, (summary) => namespaceOrder(summary.name));
312
365
  }
366
+ /**
367
+ * Sorted names of everything a namespace contributes, JSX elements included. The namespace is matched
368
+ * case-insensitively, and an unindexed one yields an empty array.
369
+ */
313
370
  symbolNames(namespaceName) {
314
371
  const namespace = this.findNamespace(namespaceName);
315
372
  if (namespace === undefined) {
@@ -318,6 +375,7 @@ class ApiReference {
318
375
  const entries = this.byNamespace.get(namespace.name) ?? [];
319
376
  return sortStrings(entries.map((entry) => entry.name));
320
377
  }
378
+ /** Renders the reference's Markdown landing page: every namespace, its import path, and its totals. */
321
379
  overview() {
322
380
  const rows = this.namespaces().map((summary) => `| ${summary.name} | \`${summary.importPath}\` | ${String(summary.symbols)} | ` +
323
381
  `${String(summary.elements)} |`);
@@ -339,6 +397,10 @@ class ApiReference {
339
397
  "",
340
398
  ].join("\n");
341
399
  }
400
+ /**
401
+ * Renders one namespace's Markdown page: its import line and its symbol names grouped by kind. The
402
+ * namespace is matched case-insensitively, and an unindexed one yields undefined.
403
+ */
342
404
  namespaceOverview(name) {
343
405
  const namespace = this.findNamespace(name);
344
406
  if (namespace === undefined) {