@gtkx/codegen 0.21.0 → 1.0.0-rc.1
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.
- package/README.md +173 -0
- package/dist/analysis/descriptor-render.d.ts +18 -0
- package/dist/analysis/descriptor-render.d.ts.map +1 -0
- package/dist/analysis/descriptor-render.js +297 -0
- package/dist/analysis/descriptor-render.js.map +1 -0
- package/dist/analysis/descriptor.d.ts +59 -0
- package/dist/analysis/descriptor.d.ts.map +1 -0
- package/dist/analysis/descriptor.js +123 -0
- package/dist/analysis/descriptor.js.map +1 -0
- package/dist/analysis/inheritance.d.ts +38 -0
- package/dist/analysis/inheritance.d.ts.map +1 -0
- package/dist/analysis/inheritance.js +193 -0
- package/dist/analysis/inheritance.js.map +1 -0
- package/dist/analysis/param-structure.d.ts +26 -0
- package/dist/analysis/param-structure.d.ts.map +1 -0
- package/dist/analysis/param-structure.js +107 -0
- package/dist/analysis/param-structure.js.map +1 -0
- package/dist/analysis/ts-type.d.ts +19 -0
- package/dist/analysis/ts-type.d.ts.map +1 -0
- package/dist/analysis/ts-type.js +65 -0
- package/dist/analysis/ts-type.js.map +1 -0
- package/dist/compile.d.ts +18 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +123 -0
- package/dist/compile.js.map +1 -0
- package/dist/docs/api-reference.d.ts +66 -0
- package/dist/docs/api-reference.d.ts.map +1 -0
- package/dist/docs/api-reference.js +299 -0
- package/dist/docs/api-reference.js.map +1 -0
- package/dist/docs/element-page.d.ts +15 -0
- package/dist/docs/element-page.d.ts.map +1 -0
- package/dist/docs/element-page.js +221 -0
- package/dist/docs/element-page.js.map +1 -0
- package/dist/docs/pipeline.d.ts +25 -0
- package/dist/docs/pipeline.d.ts.map +1 -0
- package/dist/docs/pipeline.js +130 -0
- package/dist/docs/pipeline.js.map +1 -0
- package/dist/docs/render.d.ts +32 -0
- package/dist/docs/render.d.ts.map +1 -0
- package/dist/docs/render.js +134 -0
- package/dist/docs/render.js.map +1 -0
- package/dist/docs/symbol-page.d.ts +41 -0
- package/dist/docs/symbol-page.d.ts.map +1 -0
- package/dist/docs/symbol-page.js +338 -0
- package/dist/docs/symbol-page.js.map +1 -0
- package/dist/fingerprint.d.ts +6 -26
- package/dist/fingerprint.d.ts.map +1 -1
- package/dist/fingerprint.js +30 -18
- package/dist/fingerprint.js.map +1 -1
- package/dist/gir/ancestry.d.ts +9 -0
- package/dist/gir/ancestry.d.ts.map +1 -0
- package/dist/gir/ancestry.js +29 -0
- package/dist/gir/ancestry.js.map +1 -0
- package/dist/gir/callback.d.ts +9 -10
- package/dist/gir/callback.d.ts.map +1 -1
- package/dist/gir/callback.js +17 -16
- package/dist/gir/callback.js.map +1 -1
- package/dist/gir/class.d.ts +22 -43
- package/dist/gir/class.d.ts.map +1 -1
- package/dist/gir/class.js +11 -23
- package/dist/gir/class.js.map +1 -1
- package/dist/gir/enum.d.ts +13 -31
- package/dist/gir/enum.d.ts.map +1 -1
- package/dist/gir/enum.js +7 -14
- package/dist/gir/enum.js.map +1 -1
- package/dist/gir/field.d.ts +10 -23
- package/dist/gir/field.d.ts.map +1 -1
- package/dist/gir/field.js +12 -18
- package/dist/gir/field.js.map +1 -1
- package/dist/gir/function.d.ts +11 -42
- package/dist/gir/function.d.ts.map +1 -1
- package/dist/gir/function.js +7 -20
- package/dist/gir/function.js.map +1 -1
- package/dist/gir/gir-path.d.ts +2 -0
- package/dist/gir/gir-path.d.ts.map +1 -0
- package/dist/gir/gir-path.js +41 -0
- package/dist/gir/gir-path.js.map +1 -0
- package/dist/gir/libraries.d.ts +4 -0
- package/dist/gir/libraries.d.ts.map +1 -0
- package/dist/gir/libraries.js +62 -0
- package/dist/gir/libraries.js.map +1 -0
- package/dist/gir/library.d.ts +37 -0
- package/dist/gir/library.d.ts.map +1 -0
- package/dist/gir/library.js +218 -0
- package/dist/gir/library.js.map +1 -0
- package/dist/gir/namespace.d.ts +36 -50
- package/dist/gir/namespace.d.ts.map +1 -1
- package/dist/gir/namespace.js +46 -36
- package/dist/gir/namespace.js.map +1 -1
- package/dist/gir/parameter.d.ts +25 -69
- package/dist/gir/parameter.d.ts.map +1 -1
- package/dist/gir/parameter.js +36 -57
- package/dist/gir/parameter.js.map +1 -1
- package/dist/gir/parse.d.ts +6 -70
- package/dist/gir/parse.d.ts.map +1 -1
- package/dist/gir/parse.js +32 -80
- package/dist/gir/parse.js.map +1 -1
- package/dist/gir/primitives.d.ts +3 -34
- package/dist/gir/primitives.d.ts.map +1 -1
- package/dist/gir/primitives.js +19 -35
- package/dist/gir/primitives.js.map +1 -1
- package/dist/gir/property.d.ts +16 -25
- package/dist/gir/property.d.ts.map +1 -1
- package/dist/gir/property.js +12 -9
- package/dist/gir/property.js.map +1 -1
- package/dist/gir/record.d.ts +27 -0
- package/dist/gir/record.d.ts.map +1 -0
- package/dist/gir/record.js +25 -0
- package/dist/gir/record.js.map +1 -0
- package/dist/gir/size.d.ts +10 -57
- package/dist/gir/size.d.ts.map +1 -1
- package/dist/gir/size.js +0 -25
- package/dist/gir/size.js.map +1 -1
- package/dist/gir/type-id.d.ts +49 -0
- package/dist/gir/type-id.d.ts.map +1 -0
- package/dist/gir/type-id.js +8 -0
- package/dist/gir/type-id.js.map +1 -0
- package/dist/gir/type-ref.d.ts +3 -77
- package/dist/gir/type-ref.d.ts.map +1 -1
- package/dist/gir/type-ref.js +35 -65
- package/dist/gir/type-ref.js.map +1 -1
- package/dist/gir/type.d.ts +33 -0
- package/dist/gir/type.d.ts.map +1 -0
- package/dist/gir/type.js +2 -0
- package/dist/gir/type.js.map +1 -0
- package/dist/index.d.ts +5 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -11
- package/dist/index.js.map +1 -1
- package/dist/khronos/args.d.ts +30 -0
- package/dist/khronos/args.d.ts.map +1 -0
- package/dist/khronos/args.js +150 -0
- package/dist/khronos/args.js.map +1 -0
- package/dist/khronos/jsdoc.d.ts +21 -0
- package/dist/khronos/jsdoc.d.ts.map +1 -0
- package/dist/khronos/jsdoc.js +59 -0
- package/dist/khronos/jsdoc.js.map +1 -0
- package/dist/khronos/model.d.ts +37 -0
- package/dist/khronos/model.d.ts.map +1 -0
- package/dist/khronos/model.js +132 -0
- package/dist/khronos/model.js.map +1 -0
- package/dist/khronos/modules.d.ts +11 -0
- package/dist/khronos/modules.d.ts.map +1 -0
- package/dist/khronos/modules.js +58 -0
- package/dist/khronos/modules.js.map +1 -0
- package/dist/khronos/parse.d.ts +9 -0
- package/dist/khronos/parse.d.ts.map +1 -0
- package/dist/khronos/parse.js +61 -0
- package/dist/khronos/parse.js.map +1 -0
- package/dist/khronos/pipeline.d.ts +24 -0
- package/dist/khronos/pipeline.d.ts.map +1 -0
- package/dist/khronos/pipeline.js +182 -0
- package/dist/khronos/pipeline.js.map +1 -0
- package/dist/khronos/plan.d.ts +80 -0
- package/dist/khronos/plan.d.ts.map +1 -0
- package/dist/khronos/plan.js +136 -0
- package/dist/khronos/plan.js.map +1 -0
- package/dist/khronos/render.d.ts +16 -0
- package/dist/khronos/render.d.ts.map +1 -0
- package/dist/khronos/render.js +158 -0
- package/dist/khronos/render.js.map +1 -0
- package/dist/khronos/select.d.ts +15 -0
- package/dist/khronos/select.d.ts.map +1 -0
- package/dist/khronos/select.js +45 -0
- package/dist/khronos/select.js.map +1 -0
- package/dist/runner.d.ts +29 -47
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +78 -53
- package/dist/runner.js.map +1 -1
- package/dist/store/compile-store.d.ts +9 -0
- package/dist/store/compile-store.d.ts.map +1 -0
- package/dist/store/compile-store.js +38 -0
- package/dist/store/compile-store.js.map +1 -0
- package/dist/store/gi/async.d.ts +4 -0
- package/dist/store/gi/async.d.ts.map +1 -0
- package/dist/store/gi/async.js +41 -0
- package/dist/store/gi/async.js.map +1 -0
- package/dist/store/gi/callables.d.ts +36 -0
- package/dist/store/gi/callables.d.ts.map +1 -0
- package/dist/store/gi/callables.js +202 -0
- package/dist/store/gi/callables.js.map +1 -0
- package/dist/store/gi/callback.d.ts +4 -0
- package/dist/store/gi/callback.d.ts.map +1 -0
- package/dist/store/gi/callback.js +14 -0
- package/dist/store/gi/callback.js.map +1 -0
- package/dist/store/gi/class-struct-record.d.ts +9 -0
- package/dist/store/gi/class-struct-record.d.ts.map +1 -0
- package/dist/store/gi/class-struct-record.js +34 -0
- package/dist/store/gi/class-struct-record.js.map +1 -0
- package/dist/store/gi/class.d.ts +4 -0
- package/dist/store/gi/class.d.ts.map +1 -0
- package/dist/store/gi/class.js +169 -0
- package/dist/store/gi/class.js.map +1 -0
- package/dist/store/gi/companion.d.ts +4 -0
- package/dist/store/gi/companion.d.ts.map +1 -0
- package/dist/store/gi/companion.js +13 -0
- package/dist/store/gi/companion.js.map +1 -0
- package/dist/store/gi/constant.d.ts +5 -0
- package/dist/store/gi/constant.d.ts.map +1 -0
- package/dist/store/gi/constant.js +18 -0
- package/dist/store/gi/constant.js.map +1 -0
- package/dist/store/gi/constructor-props.d.ts +5 -0
- package/dist/store/gi/constructor-props.d.ts.map +1 -0
- package/dist/store/gi/constructor-props.js +64 -0
- package/dist/store/gi/constructor-props.js.map +1 -0
- package/dist/store/gi/enum.d.ts +5 -0
- package/dist/store/gi/enum.d.ts.map +1 -0
- package/dist/store/gi/enum.js +38 -0
- package/dist/store/gi/enum.js.map +1 -0
- package/dist/store/gi/function.d.ts +8 -0
- package/dist/store/gi/function.d.ts.map +1 -0
- package/dist/store/gi/function.js +87 -0
- package/dist/store/gi/function.js.map +1 -0
- package/dist/store/gi/gtype-binding.d.ts +10 -0
- package/dist/store/gi/gtype-binding.d.ts.map +1 -0
- package/dist/store/gi/gtype-binding.js +20 -0
- package/dist/store/gi/gtype-binding.js.map +1 -0
- package/dist/store/gi/interface.d.ts +4 -0
- package/dist/store/gi/interface.d.ts.map +1 -0
- package/dist/store/gi/interface.js +99 -0
- package/dist/store/gi/interface.js.map +1 -0
- package/dist/store/gi/item-comparators.d.ts +6 -0
- package/dist/store/gi/item-comparators.d.ts.map +1 -0
- package/dist/store/gi/item-comparators.js +76 -0
- package/dist/store/gi/item-comparators.js.map +1 -0
- package/dist/store/gi/method.d.ts +24 -0
- package/dist/store/gi/method.d.ts.map +1 -0
- package/dist/store/gi/method.js +279 -0
- package/dist/store/gi/method.js.map +1 -0
- package/dist/store/gi/param-marshal.d.ts +9 -0
- package/dist/store/gi/param-marshal.d.ts.map +1 -0
- package/dist/store/gi/param-marshal.js +37 -0
- package/dist/store/gi/param-marshal.js.map +1 -0
- package/dist/store/gi/pipeline.d.ts +4 -0
- package/dist/store/gi/pipeline.d.ts.map +1 -0
- package/dist/store/gi/pipeline.js +80 -0
- package/dist/store/gi/pipeline.js.map +1 -0
- package/dist/store/gi/properties.d.ts +5 -0
- package/dist/store/gi/properties.d.ts.map +1 -0
- package/dist/store/gi/properties.js +30 -0
- package/dist/store/gi/properties.js.map +1 -0
- package/dist/store/gi/property-accessor.d.ts +26 -0
- package/dist/store/gi/property-accessor.d.ts.map +1 -0
- package/dist/store/gi/property-accessor.js +132 -0
- package/dist/store/gi/property-accessor.js.map +1 -0
- package/dist/store/gi/record-constructor.d.ts +5 -0
- package/dist/store/gi/record-constructor.d.ts.map +1 -0
- package/dist/store/gi/record-constructor.js +65 -0
- package/dist/store/gi/record-constructor.js.map +1 -0
- package/dist/store/gi/record-field-accessor.d.ts +25 -0
- package/dist/store/gi/record-field-accessor.d.ts.map +1 -0
- package/dist/store/gi/record-field-accessor.js +288 -0
- package/dist/store/gi/record-field-accessor.js.map +1 -0
- package/dist/store/gi/record-layout.d.ts +14 -0
- package/dist/store/gi/record-layout.d.ts.map +1 -0
- package/dist/store/gi/record-layout.js +96 -0
- package/dist/store/gi/record-layout.js.map +1 -0
- package/dist/store/gi/record.d.ts +4 -0
- package/dist/store/gi/record.d.ts.map +1 -0
- package/dist/store/gi/record.js +59 -0
- package/dist/store/gi/record.js.map +1 -0
- package/dist/store/gi/registration.d.ts +16 -0
- package/dist/store/gi/registration.d.ts.map +1 -0
- package/dist/store/gi/registration.js +20 -0
- package/dist/store/gi/registration.js.map +1 -0
- package/dist/store/gi/return-wrap.d.ts +10 -0
- package/dist/store/gi/return-wrap.d.ts.map +1 -0
- package/dist/store/gi/return-wrap.js +46 -0
- package/dist/store/gi/return-wrap.js.map +1 -0
- package/dist/store/gi/runtime-override.d.ts +3 -0
- package/dist/store/gi/runtime-override.d.ts.map +1 -0
- package/dist/{writers → store/gi}/runtime-override.js +0 -15
- package/dist/store/gi/runtime-override.js.map +1 -0
- package/dist/store/gi/signal.d.ts +5 -0
- package/dist/store/gi/signal.d.ts.map +1 -0
- package/dist/store/gi/signal.js +233 -0
- package/dist/store/gi/signal.js.map +1 -0
- package/dist/store/gi/vtable.d.ts +4 -0
- package/dist/store/gi/vtable.d.ts.map +1 -0
- package/dist/store/gi/vtable.js +78 -0
- package/dist/store/gi/vtable.js.map +1 -0
- package/dist/store/gi-store.d.ts +9 -0
- package/dist/store/gi-store.d.ts.map +1 -0
- package/dist/store/gi-store.js +57 -0
- package/dist/store/gi-store.js.map +1 -0
- package/dist/store/jsx-store.d.ts +5 -0
- package/dist/store/jsx-store.d.ts.map +1 -0
- package/dist/store/jsx-store.js +23 -0
- package/dist/store/jsx-store.js.map +1 -0
- package/dist/store/react/built-ins.d.ts +9 -0
- package/dist/store/react/built-ins.d.ts.map +1 -0
- package/dist/store/react/built-ins.js +226 -0
- package/dist/store/react/built-ins.js.map +1 -0
- package/dist/store/react/element-components.d.ts +15 -0
- package/dist/store/react/element-components.d.ts.map +1 -0
- package/dist/store/react/element-components.js +92 -0
- package/dist/store/react/element-components.js.map +1 -0
- package/dist/store/react/element-prop-types.d.ts +19 -0
- package/dist/store/react/element-prop-types.d.ts.map +1 -0
- package/dist/store/react/element-prop-types.js +244 -0
- package/dist/store/react/element-prop-types.js.map +1 -0
- package/dist/store/react/element-props.d.ts +4 -0
- package/dist/store/react/element-props.d.ts.map +1 -0
- package/dist/store/react/element-props.js +178 -0
- package/dist/store/react/element-props.js.map +1 -0
- package/dist/store/react/gir-index.d.ts +25 -0
- package/dist/store/react/gir-index.d.ts.map +1 -0
- package/dist/store/react/gir-index.js +55 -0
- package/dist/store/react/gir-index.js.map +1 -0
- package/dist/store/react/intrinsic-elements.d.ts +26 -0
- package/dist/store/react/intrinsic-elements.d.ts.map +1 -0
- package/dist/store/react/intrinsic-elements.js +107 -0
- package/dist/store/react/intrinsic-elements.js.map +1 -0
- package/dist/store/react/jsx.d.ts +18 -0
- package/dist/store/react/jsx.d.ts.map +1 -0
- package/dist/store/react/jsx.js +203 -0
- package/dist/store/react/jsx.js.map +1 -0
- package/dist/store/react/metadata.d.ts +4 -0
- package/dist/store/react/metadata.d.ts.map +1 -0
- package/dist/store/react/metadata.js +174 -0
- package/dist/store/react/metadata.js.map +1 -0
- package/dist/store/react/pipeline.d.ts +14 -0
- package/dist/store/react/pipeline.d.ts.map +1 -0
- package/dist/store/react/pipeline.js +60 -0
- package/dist/store/react/pipeline.js.map +1 -0
- package/dist/store/react/props.d.ts +36 -0
- package/dist/store/react/props.d.ts.map +1 -0
- package/dist/store/react/props.js +133 -0
- package/dist/store/react/props.js.map +1 -0
- package/dist/store/store-fs.d.ts +41 -0
- package/dist/store/store-fs.d.ts.map +1 -0
- package/dist/store/store-fs.js +71 -0
- package/dist/store/store-fs.js.map +1 -0
- package/dist/writer/context.d.ts +16 -0
- package/dist/writer/context.d.ts.map +1 -0
- package/dist/writer/context.js +44 -0
- package/dist/writer/context.js.map +1 -0
- package/dist/writer/doc.d.ts +2 -0
- package/dist/writer/doc.d.ts.map +1 -0
- package/dist/writer/doc.js +12 -0
- package/dist/writer/doc.js.map +1 -0
- package/dist/writer/emit.d.ts +8 -0
- package/dist/writer/emit.d.ts.map +1 -0
- package/dist/writer/emit.js +21 -0
- package/dist/writer/emit.js.map +1 -0
- package/dist/writer/gtk-doc.d.ts +2 -0
- package/dist/writer/gtk-doc.d.ts.map +1 -0
- package/dist/writer/gtk-doc.js +67 -0
- package/dist/writer/gtk-doc.js.map +1 -0
- package/dist/writer/imports.d.ts +10 -0
- package/dist/writer/imports.d.ts.map +1 -0
- package/dist/writer/imports.js +50 -0
- package/dist/writer/imports.js.map +1 -0
- package/dist/writer/module.d.ts +15 -0
- package/dist/writer/module.d.ts.map +1 -0
- package/dist/writer/module.js +46 -0
- package/dist/writer/module.js.map +1 -0
- package/overrides/cairo/context.ts.ejs +1269 -0
- package/overrides/cairo/font-face.ts.ejs +151 -0
- package/overrides/cairo/font-options.ts.ejs +199 -0
- package/overrides/cairo/image-surface.ts.ejs +132 -0
- package/overrides/cairo/index.ts.ejs +22 -0
- package/overrides/cairo/matrix.ts.ejs +171 -0
- package/overrides/cairo/pattern.ts.ejs +476 -0
- package/overrides/cairo/recording-surface.ts.ejs +102 -0
- package/overrides/cairo/region.ts.ejs +237 -0
- package/overrides/cairo/scaled-font.ts.ejs +330 -0
- package/overrides/cairo/surface.ts.ejs +296 -0
- package/overrides/gdk/index.ts.ejs +2 -0
- package/overrides/gdk/rgba.ts.ejs +11 -0
- package/overrides/gobject/index.ts.ejs +29 -0
- package/overrides/gobject/object.ts.ejs +51 -0
- package/overrides/gobject/value.ts.ejs +17 -0
- package/overrides/graphene/index.ts.ejs +2 -0
- package/overrides/graphene/structs.ts.ejs +37 -0
- package/overrides/gtk/constants.ts.ejs +3 -0
- package/overrides/gtk/index.ts.ejs +2 -0
- package/package.json +15 -15
- package/src/analysis/descriptor-render.ts +407 -0
- package/src/analysis/descriptor.ts +263 -0
- package/src/analysis/inheritance.ts +242 -0
- package/src/analysis/param-structure.ts +127 -0
- package/src/analysis/ts-type.ts +88 -0
- package/src/compile.ts +152 -0
- package/src/docs/api-reference.ts +361 -0
- package/src/docs/element-page.ts +290 -0
- package/src/docs/pipeline.ts +182 -0
- package/src/docs/render.ts +191 -0
- package/src/docs/symbol-page.ts +444 -0
- package/src/fingerprint.ts +40 -29
- package/src/gir/ancestry.ts +41 -0
- package/src/gir/callback.ts +25 -22
- package/src/gir/class.ts +31 -57
- package/src/gir/enum.ts +20 -38
- package/src/gir/field.ts +21 -36
- package/src/gir/function.ts +17 -56
- package/src/gir/gir-path.ts +49 -0
- package/src/gir/libraries.ts +77 -0
- package/src/gir/library.ts +248 -0
- package/src/gir/namespace.ts +85 -80
- package/src/gir/parameter.ts +64 -93
- package/src/gir/parse.ts +43 -95
- package/src/gir/primitives.ts +23 -45
- package/src/gir/property.ts +27 -29
- package/src/gir/record.ts +53 -0
- package/src/gir/size.ts +9 -56
- package/src/gir/type-id.ts +49 -0
- package/src/gir/type-ref.ts +35 -140
- package/src/gir/type.ts +16 -0
- package/src/index.ts +20 -15
- package/src/khronos/args.ts +202 -0
- package/src/khronos/jsdoc.ts +76 -0
- package/src/khronos/model.ts +166 -0
- package/src/khronos/modules.ts +75 -0
- package/src/khronos/parse.ts +66 -0
- package/src/khronos/pipeline.ts +234 -0
- package/src/khronos/plan.ts +191 -0
- package/src/khronos/registry/LICENSE +202 -0
- package/src/khronos/registry/gl.xml +47748 -0
- package/src/khronos/render.ts +193 -0
- package/src/khronos/select.ts +67 -0
- package/src/runner.ts +112 -75
- package/src/store/compile-store.ts +49 -0
- package/src/store/gi/async.ts +42 -0
- package/src/store/gi/callables.ts +309 -0
- package/src/store/gi/callback.ts +15 -0
- package/src/store/gi/class-struct-record.ts +40 -0
- package/src/store/gi/class.ts +212 -0
- package/src/store/gi/companion.ts +13 -0
- package/src/store/gi/constant.ts +24 -0
- package/src/store/gi/constructor-props.ts +82 -0
- package/src/store/gi/enum.ts +49 -0
- package/src/store/gi/function.ts +107 -0
- package/src/store/gi/gtype-binding.ts +33 -0
- package/src/store/gi/interface.ts +157 -0
- package/src/store/gi/item-comparators.ts +90 -0
- package/src/store/gi/method.ts +417 -0
- package/src/store/gi/param-marshal.ts +48 -0
- package/src/store/gi/pipeline.ts +85 -0
- package/src/store/gi/properties.ts +39 -0
- package/src/store/gi/property-accessor.ts +194 -0
- package/src/store/gi/record-constructor.ts +87 -0
- package/src/store/gi/record-field-accessor.ts +394 -0
- package/src/store/gi/record-layout.ts +134 -0
- package/src/store/gi/record.ts +66 -0
- package/src/store/gi/registration.ts +38 -0
- package/src/store/gi/return-wrap.ts +52 -0
- package/src/store/gi/runtime-override.ts +36 -0
- package/src/store/gi/signal.ts +310 -0
- package/src/store/gi/vtable.ts +99 -0
- package/src/store/gi-store.ts +79 -0
- package/src/store/jsx-store.ts +27 -0
- package/src/store/react/built-ins.ts +260 -0
- package/src/store/react/element-components.ts +138 -0
- package/src/store/react/element-prop-types.ts +280 -0
- package/src/store/react/element-props.ts +204 -0
- package/src/store/react/gir-index.ts +85 -0
- package/src/store/react/intrinsic-elements.ts +161 -0
- package/src/store/react/jsx.ts +294 -0
- package/src/store/react/metadata.ts +197 -0
- package/src/store/react/pipeline.ts +90 -0
- package/src/store/react/props.ts +197 -0
- package/src/store/store-fs.ts +112 -0
- package/src/writer/context.ts +48 -0
- package/src/writer/doc.ts +11 -0
- package/src/writer/emit.ts +26 -0
- package/src/writer/gtk-doc.ts +74 -0
- package/src/writer/imports.ts +59 -0
- package/src/writer/module.ts +45 -0
- package/LICENSE +0 -373
- package/dist/dsl/context.d.ts +0 -104
- package/dist/dsl/context.d.ts.map +0 -1
- package/dist/dsl/context.js +0 -140
- package/dist/dsl/context.js.map +0 -1
- package/dist/dsl/emit.d.ts +0 -28
- package/dist/dsl/emit.d.ts.map +0 -1
- package/dist/dsl/emit.js +0 -41
- package/dist/dsl/emit.js.map +0 -1
- package/dist/dsl/identifier.d.ts +0 -28
- package/dist/dsl/identifier.d.ts.map +0 -1
- package/dist/dsl/identifier.js +0 -45
- package/dist/dsl/identifier.js.map +0 -1
- package/dist/dsl/imports.d.ts +0 -58
- package/dist/dsl/imports.d.ts.map +0 -1
- package/dist/dsl/imports.js +0 -107
- package/dist/dsl/imports.js.map +0 -1
- package/dist/dsl/module.d.ts +0 -53
- package/dist/dsl/module.d.ts.map +0 -1
- package/dist/dsl/module.js +0 -76
- package/dist/dsl/module.js.map +0 -1
- package/dist/ffi/pipeline.d.ts +0 -19
- package/dist/ffi/pipeline.d.ts.map +0 -1
- package/dist/ffi/pipeline.js +0 -107
- package/dist/ffi/pipeline.js.map +0 -1
- package/dist/gi-store.d.ts +0 -34
- package/dist/gi-store.d.ts.map +0 -1
- package/dist/gi-store.js +0 -154
- package/dist/gi-store.js.map +0 -1
- package/dist/gir/boxed.d.ts +0 -66
- package/dist/gir/boxed.d.ts.map +0 -1
- package/dist/gir/boxed.js +0 -49
- package/dist/gir/boxed.js.map +0 -1
- package/dist/gir/qualified-name.d.ts +0 -37
- package/dist/gir/qualified-name.d.ts.map +0 -1
- package/dist/gir/qualified-name.js +0 -39
- package/dist/gir/qualified-name.js.map +0 -1
- package/dist/gir/qualify.d.ts +0 -32
- package/dist/gir/qualify.d.ts.map +0 -1
- package/dist/gir/qualify.js +0 -60
- package/dist/gir/qualify.js.map +0 -1
- package/dist/gir/repository.d.ts +0 -82
- package/dist/gir/repository.d.ts.map +0 -1
- package/dist/gir/repository.js +0 -122
- package/dist/gir/repository.js.map +0 -1
- package/dist/gir/signal.d.ts +0 -22
- package/dist/gir/signal.d.ts.map +0 -1
- package/dist/gir/signal.js +0 -20
- package/dist/gir/signal.js.map +0 -1
- package/dist/jsx-store.d.ts +0 -22
- package/dist/jsx-store.d.ts.map +0 -1
- package/dist/jsx-store.js +0 -40
- package/dist/jsx-store.js.map +0 -1
- package/dist/react/compounds-meta.d.ts +0 -18
- package/dist/react/compounds-meta.d.ts.map +0 -1
- package/dist/react/compounds-meta.js +0 -93
- package/dist/react/compounds-meta.js.map +0 -1
- package/dist/react/compounds.d.ts +0 -27
- package/dist/react/compounds.d.ts.map +0 -1
- package/dist/react/compounds.js +0 -164
- package/dist/react/compounds.js.map +0 -1
- package/dist/react/internal.d.ts +0 -14
- package/dist/react/internal.d.ts.map +0 -1
- package/dist/react/internal.js +0 -79
- package/dist/react/internal.js.map +0 -1
- package/dist/react/jsx.d.ts +0 -22
- package/dist/react/jsx.d.ts.map +0 -1
- package/dist/react/jsx.js +0 -134
- package/dist/react/jsx.js.map +0 -1
- package/dist/react/pipeline.d.ts +0 -13
- package/dist/react/pipeline.d.ts.map +0 -1
- package/dist/react/pipeline.js +0 -25
- package/dist/react/pipeline.js.map +0 -1
- package/dist/react/props.d.ts +0 -38
- package/dist/react/props.d.ts.map +0 -1
- package/dist/react/props.js +0 -231
- package/dist/react/props.js.map +0 -1
- package/dist/react/slot-props.d.ts +0 -10
- package/dist/react/slot-props.d.ts.map +0 -1
- package/dist/react/slot-props.js +0 -56
- package/dist/react/slot-props.js.map +0 -1
- package/dist/react/widgets.d.ts +0 -83
- package/dist/react/widgets.d.ts.map +0 -1
- package/dist/react/widgets.js +0 -152
- package/dist/react/widgets.js.map +0 -1
- package/dist/store-fs.d.ts +0 -109
- package/dist/store-fs.d.ts.map +0 -1
- package/dist/store-fs.js +0 -98
- package/dist/store-fs.js.map +0 -1
- package/dist/transpile.d.ts +0 -32
- package/dist/transpile.d.ts.map +0 -1
- package/dist/transpile.js +0 -63
- package/dist/transpile.js.map +0 -1
- package/dist/typecheck-store.d.ts +0 -41
- package/dist/typecheck-store.d.ts.map +0 -1
- package/dist/typecheck-store.js +0 -102
- package/dist/typecheck-store.js.map +0 -1
- package/dist/writers/alias.d.ts +0 -13
- package/dist/writers/alias.d.ts.map +0 -1
- package/dist/writers/alias.js +0 -17
- package/dist/writers/alias.js.map +0 -1
- package/dist/writers/async.d.ts +0 -22
- package/dist/writers/async.d.ts.map +0 -1
- package/dist/writers/async.js +0 -48
- package/dist/writers/async.js.map +0 -1
- package/dist/writers/boxed-constructor.d.ts +0 -26
- package/dist/writers/boxed-constructor.d.ts.map +0 -1
- package/dist/writers/boxed-constructor.js +0 -85
- package/dist/writers/boxed-constructor.js.map +0 -1
- package/dist/writers/boxed-field-accessor.d.ts +0 -18
- package/dist/writers/boxed-field-accessor.d.ts.map +0 -1
- package/dist/writers/boxed-field-accessor.js +0 -260
- package/dist/writers/boxed-field-accessor.js.map +0 -1
- package/dist/writers/boxed-layout.d.ts +0 -27
- package/dist/writers/boxed-layout.d.ts.map +0 -1
- package/dist/writers/boxed-layout.js +0 -128
- package/dist/writers/boxed-layout.js.map +0 -1
- package/dist/writers/boxed.d.ts +0 -20
- package/dist/writers/boxed.d.ts.map +0 -1
- package/dist/writers/boxed.js +0 -71
- package/dist/writers/boxed.js.map +0 -1
- package/dist/writers/callables.d.ts +0 -124
- package/dist/writers/callables.d.ts.map +0 -1
- package/dist/writers/callables.js +0 -283
- package/dist/writers/callables.js.map +0 -1
- package/dist/writers/callback.d.ts +0 -16
- package/dist/writers/callback.d.ts.map +0 -1
- package/dist/writers/callback.js +0 -38
- package/dist/writers/callback.js.map +0 -1
- package/dist/writers/class-struct-record.d.ts +0 -31
- package/dist/writers/class-struct-record.d.ts.map +0 -1
- package/dist/writers/class-struct-record.js +0 -67
- package/dist/writers/class-struct-record.js.map +0 -1
- package/dist/writers/class-struct.d.ts +0 -22
- package/dist/writers/class-struct.d.ts.map +0 -1
- package/dist/writers/class-struct.js +0 -85
- package/dist/writers/class-struct.js.map +0 -1
- package/dist/writers/class.d.ts +0 -16
- package/dist/writers/class.d.ts.map +0 -1
- package/dist/writers/class.js +0 -307
- package/dist/writers/class.js.map +0 -1
- package/dist/writers/constant.d.ts +0 -15
- package/dist/writers/constant.d.ts.map +0 -1
- package/dist/writers/constant.js +0 -23
- package/dist/writers/constant.js.map +0 -1
- package/dist/writers/constants.d.ts +0 -15
- package/dist/writers/constants.d.ts.map +0 -1
- package/dist/writers/constants.js +0 -23
- package/dist/writers/constants.js.map +0 -1
- package/dist/writers/constructor-props.d.ts +0 -32
- package/dist/writers/constructor-props.d.ts.map +0 -1
- package/dist/writers/constructor-props.js +0 -110
- package/dist/writers/constructor-props.js.map +0 -1
- package/dist/writers/enum.d.ts +0 -21
- package/dist/writers/enum.d.ts.map +0 -1
- package/dist/writers/enum.js +0 -48
- package/dist/writers/enum.js.map +0 -1
- package/dist/writers/function.d.ts +0 -40
- package/dist/writers/function.d.ts.map +0 -1
- package/dist/writers/function.js +0 -127
- package/dist/writers/function.js.map +0 -1
- package/dist/writers/gtype-binding.d.ts +0 -19
- package/dist/writers/gtype-binding.d.ts.map +0 -1
- package/dist/writers/gtype-binding.js +0 -40
- package/dist/writers/gtype-binding.js.map +0 -1
- package/dist/writers/inheritance.d.ts +0 -48
- package/dist/writers/inheritance.d.ts.map +0 -1
- package/dist/writers/inheritance.js +0 -90
- package/dist/writers/inheritance.js.map +0 -1
- package/dist/writers/interface.d.ts +0 -16
- package/dist/writers/interface.d.ts.map +0 -1
- package/dist/writers/interface.js +0 -155
- package/dist/writers/interface.js.map +0 -1
- package/dist/writers/method.d.ts +0 -150
- package/dist/writers/method.d.ts.map +0 -1
- package/dist/writers/method.js +0 -510
- package/dist/writers/method.js.map +0 -1
- package/dist/writers/param-classify.d.ts +0 -93
- package/dist/writers/param-classify.d.ts.map +0 -1
- package/dist/writers/param-classify.js +0 -163
- package/dist/writers/param-classify.js.map +0 -1
- package/dist/writers/property-accessor.d.ts +0 -19
- package/dist/writers/property-accessor.d.ts.map +0 -1
- package/dist/writers/property-accessor.js +0 -117
- package/dist/writers/property-accessor.js.map +0 -1
- package/dist/writers/registration.d.ts +0 -27
- package/dist/writers/registration.d.ts.map +0 -1
- package/dist/writers/registration.js +0 -30
- package/dist/writers/registration.js.map +0 -1
- package/dist/writers/return-wrap.d.ts +0 -39
- package/dist/writers/return-wrap.d.ts.map +0 -1
- package/dist/writers/return-wrap.js +0 -152
- package/dist/writers/return-wrap.js.map +0 -1
- package/dist/writers/runtime-override.d.ts +0 -18
- package/dist/writers/runtime-override.d.ts.map +0 -1
- package/dist/writers/runtime-override.js.map +0 -1
- package/dist/writers/signal.d.ts +0 -21
- package/dist/writers/signal.d.ts.map +0 -1
- package/dist/writers/signal.js +0 -260
- package/dist/writers/signal.js.map +0 -1
- package/dist/writers/ts-type.d.ts +0 -50
- package/dist/writers/ts-type.d.ts.map +0 -1
- package/dist/writers/ts-type.js +0 -75
- package/dist/writers/ts-type.js.map +0 -1
- package/dist/writers/types-ts.d.ts +0 -27
- package/dist/writers/types-ts.d.ts.map +0 -1
- package/dist/writers/types-ts.js +0 -97
- package/dist/writers/types-ts.js.map +0 -1
- package/dist/writers/value.d.ts +0 -89
- package/dist/writers/value.d.ts.map +0 -1
- package/dist/writers/value.js +0 -402
- package/dist/writers/value.js.map +0 -1
- package/src/dsl/context.ts +0 -146
- package/src/dsl/emit.ts +0 -42
- package/src/dsl/identifier.ts +0 -52
- package/src/dsl/imports.ts +0 -109
- package/src/dsl/module.ts +0 -75
- package/src/ffi/pipeline.ts +0 -113
- package/src/gi-store.ts +0 -199
- package/src/gir/boxed.ts +0 -94
- package/src/gir/qualified-name.ts +0 -55
- package/src/gir/qualify.ts +0 -64
- package/src/gir/repository.ts +0 -149
- package/src/gir/signal.ts +0 -36
- package/src/jsx-store.ts +0 -53
- package/src/react/compounds-meta.ts +0 -99
- package/src/react/compounds.ts +0 -204
- package/src/react/internal.ts +0 -91
- package/src/react/jsx.ts +0 -155
- package/src/react/pipeline.ts +0 -29
- package/src/react/props.ts +0 -307
- package/src/react/slot-props.ts +0 -57
- package/src/react/widgets.ts +0 -185
- package/src/store-fs.ts +0 -157
- package/src/transpile.ts +0 -80
- package/src/typecheck-store.ts +0 -136
- package/src/writers/alias.ts +0 -19
- package/src/writers/async.ts +0 -44
- package/src/writers/boxed-constructor.ts +0 -105
- package/src/writers/boxed-field-accessor.ts +0 -306
- package/src/writers/boxed-layout.ts +0 -166
- package/src/writers/boxed.ts +0 -77
- package/src/writers/callables.ts +0 -339
- package/src/writers/callback.ts +0 -40
- package/src/writers/class-struct-record.ts +0 -75
- package/src/writers/class-struct.ts +0 -96
- package/src/writers/class.ts +0 -384
- package/src/writers/constant.ts +0 -29
- package/src/writers/constructor-props.ts +0 -130
- package/src/writers/enum.ts +0 -53
- package/src/writers/function.ts +0 -136
- package/src/writers/gtype-binding.ts +0 -48
- package/src/writers/inheritance.ts +0 -104
- package/src/writers/interface.ts +0 -168
- package/src/writers/method.ts +0 -678
- package/src/writers/param-classify.ts +0 -178
- package/src/writers/property-accessor.ts +0 -139
- package/src/writers/registration.ts +0 -42
- package/src/writers/return-wrap.ts +0 -180
- package/src/writers/runtime-override.ts +0 -59
- package/src/writers/signal.ts +0 -318
- package/src/writers/ts-type.ts +0 -115
- package/src/writers/value.ts +0 -485
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { PRIMITIVE_TS_TYPE } from "../gir/primitives.js";
|
|
2
|
+
import { isClassStructRecord } from "../store/gi/class-struct-record.js";
|
|
3
|
+
import { gtypeTsType } from "../store/gi/gtype-binding.js";
|
|
4
|
+
const willEmitEntity = (library, type) => {
|
|
5
|
+
switch (type.kind) {
|
|
6
|
+
case "callback":
|
|
7
|
+
return type.value.introspectable && type.value.name.length > 0;
|
|
8
|
+
case "record":
|
|
9
|
+
return (type.value.introspectable &&
|
|
10
|
+
!type.value.isVtable &&
|
|
11
|
+
type.value.name.length > 0 &&
|
|
12
|
+
!isClassStructRecord(library, type.namespace.name, type.value));
|
|
13
|
+
default:
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const renderBaseTypeFor = (library, target, ref) => {
|
|
18
|
+
if (ref === undefined)
|
|
19
|
+
return "void";
|
|
20
|
+
const type = library.typeOf(ref);
|
|
21
|
+
const name = library.nameOf(ref);
|
|
22
|
+
if (type === undefined)
|
|
23
|
+
return renderNamedType(target, undefined, name);
|
|
24
|
+
switch (type.kind) {
|
|
25
|
+
case "primitive":
|
|
26
|
+
return type.category === "gtype" ? target.renderGtype() : PRIMITIVE_TS_TYPE[type.category];
|
|
27
|
+
case "varargs":
|
|
28
|
+
return "unknown[]";
|
|
29
|
+
case "callback":
|
|
30
|
+
case "class":
|
|
31
|
+
case "interface":
|
|
32
|
+
case "record":
|
|
33
|
+
case "enum":
|
|
34
|
+
case "alias":
|
|
35
|
+
return renderNamedType(target, type, willEmitEntity(library, type) ? name : undefined);
|
|
36
|
+
case "carray":
|
|
37
|
+
return `${renderBaseTypeFor(library, target, type.element)}[]`;
|
|
38
|
+
case "list":
|
|
39
|
+
if (type.flavor === "gbytearray" && target.byteArrayAsNumber)
|
|
40
|
+
return "number[]";
|
|
41
|
+
return `${renderBaseTypeFor(library, target, type.element)}[]`;
|
|
42
|
+
case "hashtable": {
|
|
43
|
+
const key = renderBaseTypeFor(library, target, type.key);
|
|
44
|
+
const value = renderBaseTypeFor(library, target, type.value);
|
|
45
|
+
return target.containerStyle === "record" ? `Record<${key}, ${value}>` : `Map<${key}, ${value}>`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const renderNamedType = (target, resolved, name) => {
|
|
50
|
+
if (name === undefined)
|
|
51
|
+
return resolved?.kind === "callback" ? target.callbackType : "unknown";
|
|
52
|
+
return target.renderNamed(resolved, name);
|
|
53
|
+
};
|
|
54
|
+
const moduleTarget = (context) => ({
|
|
55
|
+
containerStyle: "map",
|
|
56
|
+
callbackType: "((...args: any[]) => any)",
|
|
57
|
+
byteArrayAsNumber: true,
|
|
58
|
+
renderNamed: (_resolved, name) => context.qualify(name.namespaceName, name.typeName),
|
|
59
|
+
renderGtype: () => gtypeTsType(context),
|
|
60
|
+
});
|
|
61
|
+
export const renderTsType = (context, ref, isNullable = false) => {
|
|
62
|
+
const base = renderBaseTypeFor(context.library, moduleTarget(context), ref);
|
|
63
|
+
return isNullable ? `${base} | null` : base;
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=ts-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-type.js","sourceRoot":"","sources":["../../src/analysis/ts-type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAgB3D,M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CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,OAAsB,EAAgB,EAAE,CAAC,CAAC;IAC5D,cAAc,EAAE,KAAK;IACrB,YAAY,EAAE,2BAA2B;IACzC,iBAAiB,EAAE,IAAI;IACvB,WAAW,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpF,WAAW,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC;CAC1C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAsB,EAAE,GAAuB,EAAE,UAAU,GAAG,KAAK,EAAU,EAAE;IACxG,MAAM,IAAI,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC;IAC5E,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import type { Library } from \"../gir/library.js\";\nimport { PRIMITIVE_TS_TYPE } from \"../gir/primitives.js\";\nimport type { EntityType, GirType } from \"../gir/type.js\";\nimport type { TypeId } from \"../gir/type-id.js\";\nimport { isClassStructRecord } from \"../store/gi/class-struct-record.js\";\nimport { gtypeTsType } from \"../store/gi/gtype-binding.js\";\nimport type { ModuleContext } from \"../writer/context.js\";\n\ntype ReferenceName = {\n namespaceName: string;\n typeName: string;\n};\n\nexport type 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 = (library: Library, type: EntityType): boolean => {\n switch (type.kind) {\n case \"callback\":\n return type.value.introspectable && type.value.name.length > 0;\n case \"record\":\n return (\n type.value.introspectable &&\n !type.value.isVtable &&\n type.value.name.length > 0 &&\n !isClassStructRecord(library, type.namespace.name, type.value)\n );\n default:\n return true;\n }\n};\n\nexport const renderBaseTypeFor = (library: Library, target: TsTypeTarget, ref: TypeId | undefined): string => {\n if (ref === undefined) return \"void\";\n const type = library.typeOf(ref);\n const name = library.nameOf(ref);\n if (type === undefined) return renderNamedType(target, undefined, name);\n switch (type.kind) {\n case \"primitive\":\n return type.category === \"gtype\" ? target.renderGtype() : PRIMITIVE_TS_TYPE[type.category];\n case \"varargs\":\n return \"unknown[]\";\n case \"callback\":\n case \"class\":\n case \"interface\":\n case \"record\":\n case \"enum\":\n case \"alias\":\n return renderNamedType(target, type, willEmitEntity(library, type) ? name : undefined);\n case \"carray\":\n return `${renderBaseTypeFor(library, target, type.element)}[]`;\n case \"list\":\n if (type.flavor === \"gbytearray\" && target.byteArrayAsNumber) return \"number[]\";\n return `${renderBaseTypeFor(library, target, type.element)}[]`;\n case \"hashtable\": {\n const key = renderBaseTypeFor(library, target, type.key);\n const value = renderBaseTypeFor(library, target, type.value);\n return target.containerStyle === \"record\" ? `Record<${key}, ${value}>` : `Map<${key}, ${value}>`;\n }\n }\n};\n\nconst renderNamedType = (\n target: TsTypeTarget,\n resolved: GirType | undefined,\n name: ReferenceName | undefined,\n): string => {\n if (name === undefined) return resolved?.kind === \"callback\" ? target.callbackType : \"unknown\";\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\nexport const renderTsType = (context: ModuleContext, ref: TypeId | undefined, isNullable = false): string => {\n const base = renderBaseTypeFor(context.library, moduleTarget(context), ref);\n return isNullable ? `${base} | null` : base;\n};\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type SourceModule = {
|
|
2
|
+
fileName: string;
|
|
3
|
+
source: string;
|
|
4
|
+
};
|
|
5
|
+
export type CompileProjectParams = {
|
|
6
|
+
projectDir: string;
|
|
7
|
+
fileNames: string[];
|
|
8
|
+
compilerOptions: Record<string, unknown>;
|
|
9
|
+
label: string;
|
|
10
|
+
paths?: Record<string, string[]>;
|
|
11
|
+
};
|
|
12
|
+
export declare const compileProject: (params: CompileProjectParams) => void;
|
|
13
|
+
export declare const checkModules: (params: {
|
|
14
|
+
modules: SourceModule[];
|
|
15
|
+
resolveFrom: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}) => void;
|
|
18
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,YAAY,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IAC/B,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;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACpC,CAAC;AA+EF,eAAO,MAAM,cAAc,WAAY,oBAAoB,KAAG,IA2B7D,CAAC;AAQF,eAAO,MAAM,YAAY,WAAY;IAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,KAAG,IAmBtG,CAAC"}
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const BASE_COMPILER_OPTIONS = {
|
|
7
|
+
module: "esnext",
|
|
8
|
+
moduleResolution: "bundler",
|
|
9
|
+
target: "esnext",
|
|
10
|
+
lib: ["esnext"],
|
|
11
|
+
jsx: "react-jsx",
|
|
12
|
+
jsxImportSource: "react",
|
|
13
|
+
customConditions: ["source"],
|
|
14
|
+
strict: true,
|
|
15
|
+
exactOptionalPropertyTypes: true,
|
|
16
|
+
noUncheckedIndexedAccess: true,
|
|
17
|
+
noImplicitReturns: true,
|
|
18
|
+
noFallthroughCasesInSwitch: true,
|
|
19
|
+
allowUnreachableCode: false,
|
|
20
|
+
forceConsistentCasingInFileNames: true,
|
|
21
|
+
resolveJsonModule: true,
|
|
22
|
+
skipLibCheck: true,
|
|
23
|
+
types: ["node"],
|
|
24
|
+
};
|
|
25
|
+
const codegenModules = () => dirname(dirname(dirname(require.resolve("@types/node/package.json"))));
|
|
26
|
+
const linkToolingModules = (projectDir) => {
|
|
27
|
+
const link = join(projectDir, "node_modules");
|
|
28
|
+
if (existsSync(link))
|
|
29
|
+
return () => { };
|
|
30
|
+
symlinkSync(codegenModules(), link, "junction");
|
|
31
|
+
return () => rmSync(link, { force: true });
|
|
32
|
+
};
|
|
33
|
+
const tscBin = () => join(dirname(require.resolve("typescript/package.json")), "bin", "tsc");
|
|
34
|
+
const runTsc = (tsconfigPath, cwd) => {
|
|
35
|
+
try {
|
|
36
|
+
execFileSync(process.execPath, [tscBin(), "--pretty", "false", "-p", tsconfigPath], {
|
|
37
|
+
cwd,
|
|
38
|
+
encoding: "utf8",
|
|
39
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
40
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
41
|
+
});
|
|
42
|
+
return { code: 0, output: "" };
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const { status, stdout = "", stderr = "", } = error;
|
|
46
|
+
return { code: typeof status === "number" ? status : 1, output: `${stdout}\n${stderr}` };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const DIAGNOSTIC_LINE = /^(.+?)\((\d+),(\d+)\): error TS(\d+): (.*)$/;
|
|
50
|
+
const parseDiagnostics = (output, projectDir) => {
|
|
51
|
+
const diagnostics = [];
|
|
52
|
+
for (const raw of output.split(/\r?\n/)) {
|
|
53
|
+
const match = DIAGNOSTIC_LINE.exec(raw);
|
|
54
|
+
if (match === null)
|
|
55
|
+
continue;
|
|
56
|
+
const [, filePart, line, column, code, message] = match;
|
|
57
|
+
if (filePart === undefined || line === undefined || column === undefined || code === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
const file = resolve(projectDir, filePart);
|
|
60
|
+
const rel = relative(projectDir, file);
|
|
61
|
+
if (rel.startsWith("..") || isAbsolute(rel) || rel.split(/[/\\]/).includes("node_modules"))
|
|
62
|
+
continue;
|
|
63
|
+
diagnostics.push({ file, line, column, code, message: (message ?? "").trim() });
|
|
64
|
+
}
|
|
65
|
+
return diagnostics;
|
|
66
|
+
};
|
|
67
|
+
const formatDiagnostics = (label, projectDir, diagnostics) => {
|
|
68
|
+
const messages = diagnostics.map((diagnostic) => `${relative(projectDir, diagnostic.file)}:${diagnostic.line}:${diagnostic.column} - ${diagnostic.message} (TS${diagnostic.code})`);
|
|
69
|
+
return `Type checking ${label} found ${diagnostics.length} error(s):\n${messages.join("\n")}`;
|
|
70
|
+
};
|
|
71
|
+
export const compileProject = (params) => {
|
|
72
|
+
const tsconfigPath = join(params.projectDir, "tsconfig.json");
|
|
73
|
+
const unlinkToolingModules = linkToolingModules(params.projectDir);
|
|
74
|
+
try {
|
|
75
|
+
writeFileSync(tsconfigPath, JSON.stringify({
|
|
76
|
+
compilerOptions: {
|
|
77
|
+
...BASE_COMPILER_OPTIONS,
|
|
78
|
+
...params.compilerOptions,
|
|
79
|
+
...(params.paths === undefined ? {} : { paths: params.paths }),
|
|
80
|
+
},
|
|
81
|
+
files: params.fileNames.map((name) => `./${name}`),
|
|
82
|
+
}));
|
|
83
|
+
const { code, output } = runTsc(tsconfigPath, params.projectDir);
|
|
84
|
+
const diagnostics = parseDiagnostics(output, params.projectDir);
|
|
85
|
+
if (diagnostics.length > 0) {
|
|
86
|
+
throw new Error(formatDiagnostics(params.label, params.projectDir, diagnostics));
|
|
87
|
+
}
|
|
88
|
+
if (code !== 0) {
|
|
89
|
+
throw new Error(`Type checking ${params.label} failed:\n${output.trim()}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
unlinkToolingModules();
|
|
94
|
+
rmSync(tsconfigPath, { force: true });
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const CHECK_OPTIONS = {
|
|
98
|
+
declaration: true,
|
|
99
|
+
isolatedDeclarations: true,
|
|
100
|
+
noEmit: true,
|
|
101
|
+
};
|
|
102
|
+
export const checkModules = (params) => {
|
|
103
|
+
const checkRoot = join(params.resolveFrom, "node_modules");
|
|
104
|
+
mkdirSync(checkRoot, { recursive: true });
|
|
105
|
+
const projectDir = mkdtempSync(join(checkRoot, ".gtkx-check-"));
|
|
106
|
+
try {
|
|
107
|
+
for (const module of params.modules) {
|
|
108
|
+
const filePath = join(projectDir, module.fileName);
|
|
109
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
110
|
+
writeFileSync(filePath, module.source);
|
|
111
|
+
}
|
|
112
|
+
compileProject({
|
|
113
|
+
projectDir,
|
|
114
|
+
fileNames: params.modules.map((module) => module.fileName),
|
|
115
|
+
compilerOptions: CHECK_OPTIONS,
|
|
116
|
+
label: params.label,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
rmSync(projectDir, { recursive: true, force: true });
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 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B,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","sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, isAbsolute, join, relative, resolve } from \"node:path\";\n\nconst require = createRequire(import.meta.url);\n\nexport type SourceModule = {\n fileName: string;\n source: string;\n};\n\nexport type CompileProjectParams = {\n projectDir: string;\n fileNames: string[];\n compilerOptions: Record<string, unknown>;\n label: string;\n paths?: Record<string, 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 codegenModules = (): string => dirname(dirname(dirname(require.resolve(\"@types/node/package.json\"))));\n\nconst linkToolingModules = (projectDir: string): (() => void) => {\n const link = join(projectDir, \"node_modules\");\n if (existsSync(link)) return () => {};\n symlinkSync(codegenModules(), link, \"junction\");\n return () => rmSync(link, { force: true });\n};\n\nconst tscBin = (): string => join(dirname(require.resolve(\"typescript/package.json\")), \"bin\", \"tsc\");\n\nconst runTsc = (tsconfigPath: string, cwd: string): { code: number; output: string } => {\n try {\n execFileSync(process.execPath, [tscBin(), \"--pretty\", \"false\", \"-p\", tsconfigPath], {\n cwd,\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n maxBuffer: 64 * 1024 * 1024,\n });\n return { code: 0, output: \"\" };\n } catch (error) {\n const {\n status,\n stdout = \"\",\n stderr = \"\",\n } = error as { status?: number | null; stdout?: string; stderr?: string };\n return { code: typeof status === \"number\" ? status : 1, output: `${stdout}\\n${stderr}` };\n }\n};\n\nconst DIAGNOSTIC_LINE = /^(.+?)\\((\\d+),(\\d+)\\): error TS(\\d+): (.*)$/;\n\ntype ProjectDiagnostic = { file: string; line: string; column: string; code: string; message: string };\n\nconst parseDiagnostics = (output: string, projectDir: string): ProjectDiagnostic[] => {\n const diagnostics: ProjectDiagnostic[] = [];\n for (const raw of output.split(/\\r?\\n/)) {\n const match = DIAGNOSTIC_LINE.exec(raw);\n if (match === null) continue;\n const [, filePart, line, column, code, message] = match;\n if (filePart === undefined || line === undefined || column === undefined || code === undefined) continue;\n const file = resolve(projectDir, filePart);\n const rel = relative(projectDir, file);\n if (rel.startsWith(\"..\") || isAbsolute(rel) || rel.split(/[/\\\\]/).includes(\"node_modules\")) continue;\n diagnostics.push({ file, line, column, code, message: (message ?? \"\").trim() });\n }\n return diagnostics;\n};\n\nconst formatDiagnostics = (label: string, projectDir: string, diagnostics: ProjectDiagnostic[]): string => {\n const messages = diagnostics.map(\n (diagnostic) =>\n `${relative(projectDir, diagnostic.file)}:${diagnostic.line}:${diagnostic.column} - ${diagnostic.message} (TS${diagnostic.code})`,\n );\n return `Type checking ${label} found ${diagnostics.length} error(s):\\n${messages.join(\"\\n\")}`;\n};\n\nexport const compileProject = (params: CompileProjectParams): void => {\n const tsconfigPath = join(params.projectDir, \"tsconfig.json\");\n const unlinkToolingModules = linkToolingModules(params.projectDir);\n try {\n writeFileSync(\n tsconfigPath,\n JSON.stringify({\n compilerOptions: {\n ...BASE_COMPILER_OPTIONS,\n ...params.compilerOptions,\n ...(params.paths === undefined ? {} : { paths: params.paths }),\n },\n files: params.fileNames.map((name) => `./${name}`),\n }),\n );\n const { code, output } = runTsc(tsconfigPath, params.projectDir);\n const diagnostics = parseDiagnostics(output, params.projectDir);\n if (diagnostics.length > 0) {\n throw new Error(formatDiagnostics(params.label, params.projectDir, diagnostics));\n }\n if (code !== 0) {\n throw new Error(`Type checking ${params.label} failed:\\n${output.trim()}`);\n }\n } finally {\n unlinkToolingModules();\n rmSync(tsconfigPath, { force: true });\n }\n};\n\nconst CHECK_OPTIONS = {\n declaration: true,\n isolatedDeclarations: true,\n noEmit: true,\n};\n\nexport const 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 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 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"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ElementProp } from "@gtkx/config";
|
|
2
|
+
import { type GiSymbolEntry } from "./symbol-page.js";
|
|
3
|
+
export type ApiReferenceOptions = {
|
|
4
|
+
libraries: string[];
|
|
5
|
+
girPath: string[];
|
|
6
|
+
elementProps?: Record<string, ElementProp[]>;
|
|
7
|
+
};
|
|
8
|
+
export type ApiSymbolKind = GiSymbolEntry["kind"] | "element";
|
|
9
|
+
export declare const API_SYMBOL_KINDS: ApiSymbolKind[];
|
|
10
|
+
export type ApiSymbol = {
|
|
11
|
+
namespace: string;
|
|
12
|
+
name: string;
|
|
13
|
+
kind: ApiSymbolKind;
|
|
14
|
+
summary: string;
|
|
15
|
+
};
|
|
16
|
+
export type ApiNamespaceSummary = {
|
|
17
|
+
name: string;
|
|
18
|
+
importPath: string;
|
|
19
|
+
symbols: number;
|
|
20
|
+
elements: number;
|
|
21
|
+
};
|
|
22
|
+
export type ApiLookupResult = {
|
|
23
|
+
outcome: "page";
|
|
24
|
+
symbol: ApiSymbol;
|
|
25
|
+
markdown: string;
|
|
26
|
+
} | {
|
|
27
|
+
outcome: "ambiguous";
|
|
28
|
+
candidates: ApiSymbol[];
|
|
29
|
+
} | {
|
|
30
|
+
outcome: "notFound";
|
|
31
|
+
};
|
|
32
|
+
export type ApiSearchOptions = {
|
|
33
|
+
query: string;
|
|
34
|
+
namespace?: string;
|
|
35
|
+
kinds?: ApiSymbolKind[];
|
|
36
|
+
limit?: number;
|
|
37
|
+
};
|
|
38
|
+
declare class ApiReference {
|
|
39
|
+
private library;
|
|
40
|
+
private libraries;
|
|
41
|
+
private elementContext;
|
|
42
|
+
private entries;
|
|
43
|
+
private byQualified;
|
|
44
|
+
private byName;
|
|
45
|
+
private byNamespace;
|
|
46
|
+
private elementsByClass;
|
|
47
|
+
constructor(options: ApiReferenceOptions);
|
|
48
|
+
get girFiles(): string[];
|
|
49
|
+
private add;
|
|
50
|
+
private buildIndex;
|
|
51
|
+
private indexNamespace;
|
|
52
|
+
private indexFunctions;
|
|
53
|
+
private toApiSymbol;
|
|
54
|
+
private symbolPageOptions;
|
|
55
|
+
private renderPage;
|
|
56
|
+
private findNamespace;
|
|
57
|
+
lookup(query: string, kind?: ApiSymbolKind): ApiLookupResult;
|
|
58
|
+
search(options: ApiSearchOptions): ApiSymbol[];
|
|
59
|
+
namespaces(): ApiNamespaceSummary[];
|
|
60
|
+
symbolNames(namespaceName: string): string[];
|
|
61
|
+
overview(): string;
|
|
62
|
+
namespaceOverview(name: string): string | undefined;
|
|
63
|
+
}
|
|
64
|
+
export type { ApiReference };
|
|
65
|
+
export declare const loadApiReference: (options: ApiReferenceOptions) => ApiReference;
|
|
66
|
+
//# sourceMappingURL=api-reference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-reference.d.ts","sourceRoot":"","sources":["../../src/docs/api-reference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,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ACzB,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,cAAc,CAAqB;IAC3C,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,MAAM,CAAoC;IAClD,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,eAAe,CAA6B;IAEpD,YAAY,OAAO,EAAE,mBAAmB,EAKvC;IAED,IAAI,QAAQ,IAAI,MAAM,EAAE,CAEvB;IAED,OAAO,CAAC,GAAG;IAYX,OAAO,CAAC,UAAU;IAgBlB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,aAAa;IAQrB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,eAAe,CAmB3D;IAED,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,EAAE,CAsB7C;IAED,UAAU,IAAI,mBAAmB,EAAE,CAQlC;IAED,WAAW,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAK3C;IAED,QAAQ,IAAI,MAAM,CAiBjB;IAED,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAwBlD;CACJ;AAED,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B,eAAO,MAAM,gBAAgB,YAAa,mBAAmB,KAAG,YAAyC,CAAC"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { sortStrings, sortStringsBy, toPascalCase } from "@gtkx/utils";
|
|
2
|
+
import { Library } from "../gir/library.js";
|
|
3
|
+
import { namespaceDirectory } from "../gir/namespace.js";
|
|
4
|
+
import { dedupeCallables, isEmittableCallable } from "../store/gi/callables.js";
|
|
5
|
+
import { isClassStructRecord } from "../store/gi/class-struct-record.js";
|
|
6
|
+
import { namespaceFunctionExportName } from "../store/gi/function.js";
|
|
7
|
+
import { collectIntrinsicElementClasses } from "../store/react/intrinsic-elements.js";
|
|
8
|
+
import { createElementPageContext, renderElementPage } from "./element-page.js";
|
|
9
|
+
import { docsSignatureContext, firstSentence, namespaceOrder } from "./render.js";
|
|
10
|
+
import { renderSymbolPage } from "./symbol-page.js";
|
|
11
|
+
export const API_SYMBOL_KINDS = [
|
|
12
|
+
"element",
|
|
13
|
+
"class",
|
|
14
|
+
"interface",
|
|
15
|
+
"record",
|
|
16
|
+
"enum",
|
|
17
|
+
"callback",
|
|
18
|
+
"alias",
|
|
19
|
+
"function",
|
|
20
|
+
"constant",
|
|
21
|
+
];
|
|
22
|
+
const KIND_SECTION_TITLES = {
|
|
23
|
+
element: "JSX elements",
|
|
24
|
+
class: "Classes",
|
|
25
|
+
interface: "Interfaces",
|
|
26
|
+
record: "Records",
|
|
27
|
+
enum: "Enums",
|
|
28
|
+
callback: "Callbacks",
|
|
29
|
+
alias: "Aliases",
|
|
30
|
+
function: "Functions",
|
|
31
|
+
constant: "Constants",
|
|
32
|
+
};
|
|
33
|
+
const DEFAULT_SEARCH_LIMIT = 20;
|
|
34
|
+
const compareNames = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
35
|
+
class ApiReference {
|
|
36
|
+
library;
|
|
37
|
+
libraries;
|
|
38
|
+
elementContext;
|
|
39
|
+
entries = [];
|
|
40
|
+
byQualified = new Map();
|
|
41
|
+
byName = new Map();
|
|
42
|
+
byNamespace = new Map();
|
|
43
|
+
elementsByClass = new Map();
|
|
44
|
+
constructor(options) {
|
|
45
|
+
this.libraries = options.libraries;
|
|
46
|
+
this.library = Library.load(options.libraries, options.girPath);
|
|
47
|
+
this.elementContext = createElementPageContext(this.library, options.elementProps ?? {}, () => undefined);
|
|
48
|
+
this.buildIndex();
|
|
49
|
+
}
|
|
50
|
+
get girFiles() {
|
|
51
|
+
return this.library.girFiles;
|
|
52
|
+
}
|
|
53
|
+
add(entry) {
|
|
54
|
+
this.entries.push(entry);
|
|
55
|
+
const push = (map, key) => {
|
|
56
|
+
const list = map.get(key) ?? [];
|
|
57
|
+
list.push(entry);
|
|
58
|
+
map.set(key, list);
|
|
59
|
+
};
|
|
60
|
+
push(this.byQualified, `${entry.namespace.name}.${entry.name}`.toLowerCase());
|
|
61
|
+
push(this.byName, entry.name.toLowerCase());
|
|
62
|
+
push(this.byNamespace, entry.namespace.name);
|
|
63
|
+
}
|
|
64
|
+
buildIndex() {
|
|
65
|
+
for (const namespace of this.library.namespaces.values()) {
|
|
66
|
+
this.indexNamespace(namespace);
|
|
67
|
+
}
|
|
68
|
+
for (const element of collectIntrinsicElementClasses(this.library)) {
|
|
69
|
+
this.add({
|
|
70
|
+
kind: "element",
|
|
71
|
+
namespace: element.namespace,
|
|
72
|
+
name: element.glibName,
|
|
73
|
+
doc: element.klass.doc,
|
|
74
|
+
element,
|
|
75
|
+
});
|
|
76
|
+
this.elementsByClass.set(`${element.namespace.name}.${element.klass.name}`, element.glibName);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
indexNamespace(namespace) {
|
|
80
|
+
const entries = [
|
|
81
|
+
...classEntries(namespace),
|
|
82
|
+
...recordEntries(this.library, namespace),
|
|
83
|
+
...valueEntries(namespace),
|
|
84
|
+
];
|
|
85
|
+
for (const entry of entries) {
|
|
86
|
+
this.add(entry);
|
|
87
|
+
}
|
|
88
|
+
this.indexFunctions(namespace);
|
|
89
|
+
}
|
|
90
|
+
indexFunctions(namespace) {
|
|
91
|
+
if (namespace.sharedLibrary === undefined)
|
|
92
|
+
return;
|
|
93
|
+
const docsContext = docsSignatureContext(namespace, this.library);
|
|
94
|
+
for (const fn of dedupeCallables(namespace.functions)) {
|
|
95
|
+
if (!isEmittableCallable(docsContext, fn))
|
|
96
|
+
continue;
|
|
97
|
+
const cIdentifier = fn.cIdentifier;
|
|
98
|
+
if (cIdentifier === undefined)
|
|
99
|
+
continue;
|
|
100
|
+
const name = namespaceFunctionExportName(cIdentifier, fn.name, namespace.cSymbolPrefixes);
|
|
101
|
+
this.add({ kind: "function", namespace, name, doc: fn.doc, fn });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
toApiSymbol(entry) {
|
|
105
|
+
return {
|
|
106
|
+
namespace: entry.namespace.name,
|
|
107
|
+
name: entry.name,
|
|
108
|
+
kind: entry.kind,
|
|
109
|
+
summary: firstSentence(entry.doc),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
symbolPageOptions() {
|
|
113
|
+
return {
|
|
114
|
+
library: this.library,
|
|
115
|
+
elementNameFor: (namespaceName, className) => this.elementsByClass.get(`${namespaceName}.${className}`),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
renderPage(entry) {
|
|
119
|
+
if (entry.kind === "element")
|
|
120
|
+
return renderElementPage(entry.element, this.elementContext);
|
|
121
|
+
return renderSymbolPage(entry, this.symbolPageOptions());
|
|
122
|
+
}
|
|
123
|
+
findNamespace(name) {
|
|
124
|
+
const lower = name.toLowerCase();
|
|
125
|
+
for (const namespace of this.library.namespaces.values()) {
|
|
126
|
+
if (namespace.name.toLowerCase() === lower)
|
|
127
|
+
return namespace;
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
lookup(query, kind) {
|
|
132
|
+
const trimmed = query.trim();
|
|
133
|
+
if (trimmed.length === 0)
|
|
134
|
+
return { outcome: "notFound" };
|
|
135
|
+
const qualified = trimmed.includes(".");
|
|
136
|
+
const map = qualified ? this.byQualified : this.byName;
|
|
137
|
+
let candidates = map.get(trimmed.toLowerCase()) ?? [];
|
|
138
|
+
if (kind !== undefined)
|
|
139
|
+
candidates = candidates.filter((entry) => entry.kind === kind);
|
|
140
|
+
if (candidates.length > 1) {
|
|
141
|
+
const exact = candidates.filter((entry) => qualified ? `${entry.namespace.name}.${entry.name}` === trimmed : entry.name === trimmed);
|
|
142
|
+
if (exact.length > 0)
|
|
143
|
+
candidates = exact;
|
|
144
|
+
}
|
|
145
|
+
const entry = candidates[0];
|
|
146
|
+
if (entry === undefined)
|
|
147
|
+
return { outcome: "notFound" };
|
|
148
|
+
if (candidates.length > 1) {
|
|
149
|
+
return { outcome: "ambiguous", candidates: candidates.map((candidate) => this.toApiSymbol(candidate)) };
|
|
150
|
+
}
|
|
151
|
+
return { outcome: "page", symbol: this.toApiSymbol(entry), markdown: this.renderPage(entry) };
|
|
152
|
+
}
|
|
153
|
+
search(options) {
|
|
154
|
+
const query = options.query.trim().toLowerCase();
|
|
155
|
+
if (query.length === 0)
|
|
156
|
+
return [];
|
|
157
|
+
const limit = Math.max(1, Math.floor(options.limit ?? DEFAULT_SEARCH_LIMIT));
|
|
158
|
+
const namespaceFilter = options.namespace?.toLowerCase();
|
|
159
|
+
const scored = [];
|
|
160
|
+
for (const entry of this.entries) {
|
|
161
|
+
if (namespaceFilter !== undefined && entry.namespace.name.toLowerCase() !== namespaceFilter)
|
|
162
|
+
continue;
|
|
163
|
+
if (options.kinds !== undefined && !options.kinds.includes(entry.kind))
|
|
164
|
+
continue;
|
|
165
|
+
const score = searchScore(entry, query);
|
|
166
|
+
if (score === 0)
|
|
167
|
+
continue;
|
|
168
|
+
scored.push({ score, entry });
|
|
169
|
+
}
|
|
170
|
+
scored.sort((a, b) => b.score - a.score ||
|
|
171
|
+
a.entry.name.length - b.entry.name.length ||
|
|
172
|
+
compareNames(a.entry.name, b.entry.name) ||
|
|
173
|
+
compareNames(namespaceOrder(a.entry.namespace.name), namespaceOrder(b.entry.namespace.name)) ||
|
|
174
|
+
compareNames(a.entry.kind, b.entry.kind));
|
|
175
|
+
return scored.slice(0, limit).map((item) => this.toApiSymbol(item.entry));
|
|
176
|
+
}
|
|
177
|
+
namespaces() {
|
|
178
|
+
const summaries = [...this.byNamespace.entries()].map(([name, entries]) => ({
|
|
179
|
+
name,
|
|
180
|
+
importPath: `@gtkx/gi/${namespaceDirectory({ name })}`,
|
|
181
|
+
symbols: entries.filter((entry) => entry.kind !== "element").length,
|
|
182
|
+
elements: entries.filter((entry) => entry.kind === "element").length,
|
|
183
|
+
}));
|
|
184
|
+
return sortStringsBy(summaries, (summary) => namespaceOrder(summary.name));
|
|
185
|
+
}
|
|
186
|
+
symbolNames(namespaceName) {
|
|
187
|
+
const namespace = this.findNamespace(namespaceName);
|
|
188
|
+
if (namespace === undefined)
|
|
189
|
+
return [];
|
|
190
|
+
const entries = this.byNamespace.get(namespace.name) ?? [];
|
|
191
|
+
return sortStrings(entries.map((entry) => entry.name));
|
|
192
|
+
}
|
|
193
|
+
overview() {
|
|
194
|
+
const rows = this.namespaces().map((summary) => `| ${summary.name} | \`${summary.importPath}\` | ${summary.symbols} | ${summary.elements} |`);
|
|
195
|
+
const librariesList = this.libraries.map((library) => `\`${library}\``).join(", ");
|
|
196
|
+
return [
|
|
197
|
+
"# API Reference",
|
|
198
|
+
"",
|
|
199
|
+
`Generated bindings for ${librariesList} and the namespaces they pull in. Classes, interfaces, records, enums, callbacks, aliases, functions, and constants are imported from \`@gtkx/gi/<namespace>\`; JSX elements are imported from \`@gtkx/jsx/<namespace>\`.`,
|
|
200
|
+
"",
|
|
201
|
+
"Every symbol has a reference page addressed by its qualified name (for example `Gtk.Button`, `Gtk.Orientation`, `GLib.idleAdd`) and every JSX element by its element name (for example `GtkButton`).",
|
|
202
|
+
"",
|
|
203
|
+
"| Namespace | Import | Symbols | JSX elements |",
|
|
204
|
+
"| --- | --- | --- | --- |",
|
|
205
|
+
...rows,
|
|
206
|
+
"",
|
|
207
|
+
].join("\n");
|
|
208
|
+
}
|
|
209
|
+
namespaceOverview(name) {
|
|
210
|
+
const namespace = this.findNamespace(name);
|
|
211
|
+
if (namespace === undefined)
|
|
212
|
+
return undefined;
|
|
213
|
+
const entries = this.byNamespace.get(namespace.name) ?? [];
|
|
214
|
+
const directory = namespaceDirectory(namespace);
|
|
215
|
+
const lines = [
|
|
216
|
+
`# ${namespace.name}`,
|
|
217
|
+
"",
|
|
218
|
+
`\`\`\`ts\nimport * as ${namespace.name} from "@gtkx/gi/${directory}";\n\`\`\``,
|
|
219
|
+
];
|
|
220
|
+
for (const kind of API_SYMBOL_KINDS) {
|
|
221
|
+
const names = entries.filter((entry) => entry.kind === kind).map((entry) => entry.name);
|
|
222
|
+
if (names.length === 0)
|
|
223
|
+
continue;
|
|
224
|
+
lines.push("", `## ${KIND_SECTION_TITLES[kind]} (${names.length})`, "", sortStrings(names)
|
|
225
|
+
.map((symbolName) => `\`${symbolName}\``)
|
|
226
|
+
.join(", "));
|
|
227
|
+
}
|
|
228
|
+
lines.push("");
|
|
229
|
+
return lines.join("\n");
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export const loadApiReference = (options) => new ApiReference(options);
|
|
233
|
+
const classEntries = (namespace) => {
|
|
234
|
+
const entries = [];
|
|
235
|
+
for (const klass of [...namespace.classes, ...namespace.interfaces]) {
|
|
236
|
+
if (!klass.introspectable || klass.name.length === 0)
|
|
237
|
+
continue;
|
|
238
|
+
const kind = klass.isInterface ? "interface" : "class";
|
|
239
|
+
entries.push({ kind, namespace, name: toPascalCase(klass.name), doc: klass.doc, klass });
|
|
240
|
+
}
|
|
241
|
+
return entries;
|
|
242
|
+
};
|
|
243
|
+
const recordEntries = (library, namespace) => {
|
|
244
|
+
const entries = [];
|
|
245
|
+
for (const record of namespace.records) {
|
|
246
|
+
if (!record.introspectable || record.isVtable || record.name.length === 0)
|
|
247
|
+
continue;
|
|
248
|
+
if (isClassStructRecord(library, namespace.name, record))
|
|
249
|
+
continue;
|
|
250
|
+
entries.push({ kind: "record", namespace, name: record.name, doc: record.doc, record });
|
|
251
|
+
}
|
|
252
|
+
return entries;
|
|
253
|
+
};
|
|
254
|
+
const valueEntries = (namespace) => [
|
|
255
|
+
...namespace.enums
|
|
256
|
+
.filter((enumeration) => enumeration.introspectable)
|
|
257
|
+
.map((enumeration) => ({
|
|
258
|
+
kind: "enum",
|
|
259
|
+
namespace,
|
|
260
|
+
name: enumeration.name,
|
|
261
|
+
doc: enumeration.doc,
|
|
262
|
+
enumeration,
|
|
263
|
+
})),
|
|
264
|
+
...namespace.callbacks
|
|
265
|
+
.filter((callback) => callback.introspectable)
|
|
266
|
+
.map((callback) => ({
|
|
267
|
+
kind: "callback",
|
|
268
|
+
namespace,
|
|
269
|
+
name: callback.name,
|
|
270
|
+
doc: callback.doc,
|
|
271
|
+
callback,
|
|
272
|
+
})),
|
|
273
|
+
...namespace.aliases.map((alias) => ({
|
|
274
|
+
kind: "alias",
|
|
275
|
+
namespace,
|
|
276
|
+
name: alias.name,
|
|
277
|
+
doc: alias.doc,
|
|
278
|
+
alias,
|
|
279
|
+
})),
|
|
280
|
+
...namespace.constants.map((constant) => ({
|
|
281
|
+
kind: "constant",
|
|
282
|
+
namespace,
|
|
283
|
+
name: constant.name,
|
|
284
|
+
doc: constant.doc,
|
|
285
|
+
constant,
|
|
286
|
+
})),
|
|
287
|
+
];
|
|
288
|
+
const searchScore = (entry, query) => {
|
|
289
|
+
const name = entry.name.toLowerCase();
|
|
290
|
+
const qualified = `${entry.namespace.name.toLowerCase()}.${name}`;
|
|
291
|
+
if (name === query || qualified === query)
|
|
292
|
+
return 3;
|
|
293
|
+
if (name.startsWith(query))
|
|
294
|
+
return 2;
|
|
295
|
+
if (name.includes(query) || qualified.includes(query))
|
|
296
|
+
return 1;
|
|
297
|
+
return 0;
|
|
298
|
+
};
|
|
299
|
+
//# sourceMappingURL=api-reference.js.map
|