diff --git a/examples/README.md b/examples/README.md index 2ae76919..88dca36f 100644 --- a/examples/README.md +++ b/examples/README.md @@ -57,10 +57,10 @@ Run the client: yarn start:client ``` -## Gtk-3.0 Browser +## Gtk3 Browser ![gtk-3-browser](gtk-3-browser/preview.png) -A simple browser using Gtk-3.0 and WebKit-2.0 +A simple browser using Gtk3 and WebKit-2.0 Source: [gtk-3-browser](gtk-3-browser) Bundler: Webpack @@ -71,7 +71,7 @@ cd /examples/gtk-3-browser yarn start ``` -## Gtk-3.0 Builder +## Gtk3 Builder ![gtk-3-builder](gtk-3-builder/preview.png) Source: [gtk-3-builder](gtk-3-builder) @@ -83,7 +83,32 @@ cd /examples/gtk-3-builder yarn start ``` -## Gtk-3.0 Editor +## Gtk3 Calc +![gtk-3-calc](gtk-3-calc/preview.png) + +Source: [gtk-3-calc](gtk-3-calc) +Bundler: Esbuild + +Build and run: +```bash +cd /examples/gtk-3-calc +yarn start +``` + +## Gtk3 Clutter (TSC) +![gtk-3-clutter](gtk-3-clutter-tsc/preview.png) + +Source: [gtk-3-clutter](gtk-3-clutter-tsc) +Bundler: TSC + +Build and run: +```bash +cd /examples/gtk-3-clutter-tsc +yarn start +``` + + +## Gtk3 Editor ![gtk-3-editor](gtk-3-editor/preview.png) Source: [gtk-3-editor](gtk-3-editor) @@ -95,7 +120,7 @@ cd /examples/gtk-3-editor yarn start ``` -## Gtk-3.0 Hello Gtk +## Gtk3 Hello Gtk ![gtk-3-hello](gtk-3-hello/preview.png) Source: [gtk-3-hello](gtk-3-hello) @@ -107,7 +132,7 @@ cd /examples/gtk-3-hello yarn start ``` -## Gtk-4.0 ListStore +## Gtk4 ListStore ![gtk-4-list-store](gtk-4-list-store/preview.png) GJS example showing how to build Gtk4 applications using `Gtk.TreeView` and `Gtk.ListStore` diff --git a/examples/adw-1-hello/package.json b/examples/adw-1-hello/package.json index e280f166..53a12d17 100644 --- a/examples/adw-1-hello/package.json +++ b/examples/adw-1-hello/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/adw-1-hello-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Typescript hello-world example using Libadwaita", "type": "module", "private": true, diff --git a/examples/cairo-surfaces-tsc/main.ts b/examples/cairo-surfaces-tsc/main.ts new file mode 100644 index 00000000..6a87e986 --- /dev/null +++ b/examples/cairo-surfaces-tsc/main.ts @@ -0,0 +1,11 @@ +import Cairo from 'cairo'; + +const imageSurface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 10, 10); + +const pngSurface = Cairo.ImageSurface.createFromPNG('filename.png'); + +const pdfSurface = new Cairo.PDFSurface('filename.pdf', 32, 32); + +const psSurface = new Cairo.PSSurface('filename.ps', 32, 32); + +const svgSurface = new Cairo.SVGSurface('filename.svg', 32, 32); \ No newline at end of file diff --git a/examples/cairo-surfaces-tsc/package.json b/examples/cairo-surfaces-tsc/package.json new file mode 100644 index 00000000..f038a76d --- /dev/null +++ b/examples/cairo-surfaces-tsc/package.json @@ -0,0 +1,26 @@ +{ + "name": "@ts-for-gir-example/cairo-surfaces-tsc", + "version": "4.0.0-beta.12", + "description": "Simple cairo-surfaces GJS example", + "type": "module", + "private": true, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build:app": "tsc", + "build": "yarn build:app", + "start:app": "gjs -m dist/main.js", + "debug:app": "GTK_DEBUG=interactive yarn start:app", + "start": "yarn build && yarn start:app", + "validate": "yarn validate:types", + "validate:types": "tsc --noEmit", + "clear": "rm -rf dist @types" + }, + "author": "Pascal Garber ", + "license": "MIT", + "devDependencies": { + "typescript": "^5.5.3" + }, + "dependencies": { + "@girs/gjs": "workspace:^" + } +} diff --git a/examples/cairo-surfaces-tsc/preview.png b/examples/cairo-surfaces-tsc/preview.png new file mode 100644 index 00000000..3d05e0e0 Binary files /dev/null and b/examples/cairo-surfaces-tsc/preview.png differ diff --git a/examples/cairo-surfaces-tsc/tsconfig.json b/examples/cairo-surfaces-tsc/tsconfig.json new file mode 100644 index 00000000..d89d6540 --- /dev/null +++ b/examples/cairo-surfaces-tsc/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "types": ["@girs/gjs", "@girs/gjs/dom"], + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "bundler", + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "noImplicitThis": true, + "alwaysStrict": true, + "outDir": "./dist" + }, + "files": [ + "main.ts", + ] +} diff --git a/examples/gio-2-cat/package.json b/examples/gio-2-cat/package.json index 3cceda1a..488ef447 100644 --- a/examples/gio-2-cat/package.json +++ b/examples/gio-2-cat/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gio-2-cat-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 3 example app that shows how to use Gio-2.0 to read a file from the local file system", "main": "index.js", "type": "module", diff --git a/examples/gio-2-dbus/package.json b/examples/gio-2-dbus/package.json index a923e1cc..2fb473f8 100644 --- a/examples/gio-2-dbus/package.json +++ b/examples/gio-2-dbus/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gio-2-dbus-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "GJS example showing how to build a DBus server/client", "main": "index.js", "type": "module", diff --git a/examples/gio-2-list-model/package.json b/examples/gio-2-list-model/package.json index 0e9f9c60..a8fedb64 100644 --- a/examples/gio-2-list-model/package.json +++ b/examples/gio-2-list-model/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gio-2-list-model-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "An example of implementing the GListModel interface in GJS", "main": "index.js", "type": "module", diff --git a/examples/glib-2-spawn-command/package.json b/examples/glib-2-spawn-command/package.json index 13ba7033..4d7604f3 100644 --- a/examples/glib-2-spawn-command/package.json +++ b/examples/glib-2-spawn-command/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/glib-2-spawn-command-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "", "type": "module", "private": true, diff --git a/examples/glib-2-variant/package.json b/examples/glib-2-variant/package.json index 0bb7eeec..a1bd398a 100644 --- a/examples/glib-2-variant/package.json +++ b/examples/glib-2-variant/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/glib-2-variant-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "ts-for-gir GVariant example based on https://gjs.guide/guides/glib/gvariant.html", "type": "module", "private": true, diff --git a/examples/gtk-3-browser/package.json b/examples/gtk-3-browser/package.json index 5bd8beba..c41c898b 100644 --- a/examples/gtk-3-browser/package.json +++ b/examples/gtk-3-browser/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-3-browser-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "type": "module", "private": true, "scripts": { diff --git a/examples/gtk-3-builder/package.json b/examples/gtk-3-builder/package.json index d849eedb..1f7036fa 100644 --- a/examples/gtk-3-builder/package.json +++ b/examples/gtk-3-builder/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-3-builder-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "type": "module", "private": true, "scripts": { diff --git a/examples/gtk-3-calc/package.json b/examples/gtk-3-calc/package.json index 903cc98d..88da6cb5 100644 --- a/examples/gtk-3-calc/package.json +++ b/examples/gtk-3-calc/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-3-calc-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 3 calculator example app", "type": "module", "private": true, diff --git a/examples/gtk-3-clutter-tsc/main.ts b/examples/gtk-3-clutter-tsc/main.ts new file mode 100644 index 00000000..f00b3d16 --- /dev/null +++ b/examples/gtk-3-clutter-tsc/main.ts @@ -0,0 +1,195 @@ +#!/usr/bin/gjs + +/* +Credits: https://raw.githubusercontent.com/optimisme/gjs-examples/master/egCairo.js +GJS example showing how to build Gtk javascript applications +using Gtk and Cairo, the left example adds one Cairo actor to +Clutter, the example on the right adds one Cairo widget to GTK +using GtkClutter.Embed, Gtk.DrawingArea, Cairo.Context, +Clutter.Canvas + +Run it with: + gjs egCairo.js +*/ +import type Cairo from 'cairo'; +import Clutter from 'gi://Clutter?version=1.0'; +import GtkClutter from 'gi://GtkClutter?version=1.0'; +import Gio from 'gi://Gio'; +import GLib from 'gi://GLib'; +import Gtk from 'gi://Gtk?version=3.0'; + +// Get application folder and add it into the imports path +function getAppFileInfo() { + let stack = (new Error()).stack, + stackLine = stack?.split('\n')[1], + coincidence, path, file; + + if (!stackLine) throw new Error('Could not find current file (1)'); + + coincidence = new RegExp('@(.+):\\d+').exec(stackLine); + if (!coincidence) throw new Error('Could not find current file (2)'); + + path = coincidence[1]; + file = Gio.File.new_for_path(path); + return [file.get_path(), file.get_parent()!.get_path(), file.get_basename()]; +} +const path = getAppFileInfo()[1]; +imports.searchPath.push(path!); + +class App { + title: string; + application?: Gtk.Application; + window?: Gtk.ApplicationWindow; + constructor() { + this.title = 'Gtk3 Clutter'; + GLib.set_prgname(this.title); + } + + run(argv: string[] | null | undefined): number { + this.application = new Gtk.Application(); + this.application.connect('activate', () => { this.onActivate(); }); + this.application.connect('startup', () => { this.onStartup(); }); + return this.application.run([]); + } + + onActivate() { + this.window!.show_all(); + } + + + onStartup() { + this.initClutter(); + this.buildUI(); + }; + + initClutter() { + + GtkClutter.init(null); + Clutter.init(null); + }; + + buildUI() { + + this.window = new Gtk.ApplicationWindow({ application: this.application, + title: this.title, + default_height: 300, + default_width: 500, + window_position: Gtk.WindowPosition.CENTER }); + try { + this.window.set_icon_from_file(path + '/assets/appIcon.png'); + } catch (err) { + this.window.set_icon_name('application-x-executable'); + } + + this.window.add(this.buildBody()); + }; + + buildBody() { + + const embed = new GtkClutter.Embed(); + embed.set_size_request(250, 300); + + const area = new Gtk.DrawingArea(); + area.set_size_request(250, 300); + area.connect('draw', (area, ctx) => { this.drawRed(area, ctx as Cairo.Context); }); + + const grid = new Gtk.Grid({ column_spacing: 6, margin: 15, row_spacing: 6 }); + grid.attach(embed, 0, 0, 1, 1); + grid.attach(area, 1, 0, 1, 1); + + const stage = embed.get_stage(); + stage.backgroundColor = new Clutter.Color({ red: 255, green: 255, blue: 255, alpha: 255 }); + stage.add_child(this.getClutterActor()); + + return grid; + }; + + getClutterActor() { + + let canvas, actor; + + canvas = new Clutter.Canvas({ + height: 100, + width: 100 + }); + canvas.set_size(100,100); + canvas.connect('draw', (area, ctx) => { this.drawGreen(area, ctx as Cairo.Context); }); + canvas.invalidate(); + + actor = new Clutter.Actor({ + x: 75, y: 100, + height: 100, width: 100 + }); + actor.set_content(canvas); + + return actor; + }; + + drawRed(area: Gtk.DrawingArea, ctx: Cairo.Context) { + + // area is Gtk.DrawingArea + // ctx is Cairo.Context + + let height, width; + + height = area.get_allocated_height(); + width = area.get_allocated_width(); + + this.draw(ctx, height, width, 'red'); + }; + + drawGreen(canvas: Clutter.Canvas, ctx: Cairo.Context) { + + // canvas is Clutter.Canvas + // ctx is Cairo.Context + + let height, width; + + height = canvas.height; + width = canvas.width; + + this.draw(ctx, height, width, 'green'); + }; + + draw(ctx: Cairo.Context, height: number, width: number, color: string) { + + let xc, yc; + + xc = width / 2; + yc = height / 2; + + ctx.save(); + if (color === 'red') { + // Set black background for 'red' + ctx.setSourceRGBA(0, 0, 0, 1); + } else { + // Set grey background + ctx.setSourceRGBA(0.75, 0.75, 0.75, 1); + } + ctx.paint(); + ctx.restore(); + + if (color === 'red') { + ctx.setSourceRGBA(1, 0, 0, 1); + } else { + ctx.setSourceRGBA(0, 0.5, 0, 1); + } + + ctx.moveTo(0, 0); + ctx.lineTo(xc, yc); + ctx.lineTo(0, height); + ctx.moveTo(xc, yc); + ctx.lineTo(width, yc); + ctx.stroke(); + + return false; + }; +} + + + + +//Run the application +let app = new App(); +app.run(ARGV); + diff --git a/examples/gtk-3-clutter-tsc/package.json b/examples/gtk-3-clutter-tsc/package.json new file mode 100644 index 00000000..f3a09ab1 --- /dev/null +++ b/examples/gtk-3-clutter-tsc/package.json @@ -0,0 +1,32 @@ +{ + "name": "@ts-for-gir-example/gtk-3-clutter-tsc", + "version": "4.0.0-beta.12", + "description": "Simple GJS GTK+3 Clutter example app", + "type": "module", + "private": true, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build:app": "tsc", + "build": "yarn build:app", + "start:app": "gjs -m dist/main.js", + "debug:app": "GTK_DEBUG=interactive yarn start:app", + "start": "yarn build && yarn start:app", + "validate": "yarn validate:types", + "validate:types": "tsc --noEmit", + "clear": "rm -rf dist @types" + }, + "author": "Pascal Garber ", + "license": "MIT", + "devDependencies": { + "typescript": "^5.5.3" + }, + "dependencies": { + "@girs/clutter-1.0": "workspace:^", + "@girs/gdk-3.0": "workspace:^", + "@girs/gio-2.0": "workspace:^", + "@girs/gjs": "workspace:^", + "@girs/glib-2.0": "workspace:^", + "@girs/gtk-3.0": "workspace:^", + "@girs/gtkclutter-1.0": "workspace:^" + } +} diff --git a/examples/gtk-3-clutter-tsc/preview.png b/examples/gtk-3-clutter-tsc/preview.png new file mode 100644 index 00000000..3d05e0e0 Binary files /dev/null and b/examples/gtk-3-clutter-tsc/preview.png differ diff --git a/examples/gtk-3-clutter-tsc/tsconfig.json b/examples/gtk-3-clutter-tsc/tsconfig.json new file mode 100644 index 00000000..e41cc2aa --- /dev/null +++ b/examples/gtk-3-clutter-tsc/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "types": ["@girs/gjs", "@girs/gjs/dom", "@girs/gio-2.0", "@girs/glib-2.0", "@girs/gtk-3.0", "@girs/clutter-1.0", "@girs/gtkclutter-1.0"], + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "bundler", + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "noImplicitThis": true, + "alwaysStrict": true, + "outDir": "./dist" + }, + "files": [ + "main.ts", + ] +} diff --git a/examples/gtk-3-editor/package.json b/examples/gtk-3-editor/package.json index 843bd94d..0cd819fd 100644 --- a/examples/gtk-3-editor/package.json +++ b/examples/gtk-3-editor/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-3-editor-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "type": "module", "targets": { ".": { diff --git a/examples/gtk-3-hello-2/package.json b/examples/gtk-3-hello-2/package.json index 5b5a5d77..db24852c 100644 --- a/examples/gtk-3-hello-2/package.json +++ b/examples/gtk-3-hello-2/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-3-hello-2-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 3 example app to demonstrate how you can connect to Gtk signals", "type": "module", "private": true, diff --git a/examples/gtk-3-hello/package.json b/examples/gtk-3-hello/package.json index 8c6e0a11..122b72b7 100644 --- a/examples/gtk-3-hello/package.json +++ b/examples/gtk-3-hello/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-3-hello-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "type": "module", "private": true, "scripts": { diff --git a/examples/gtk-3-template/package.json b/examples/gtk-3-template/package.json index 7ae8df67..17add9ee 100644 --- a/examples/gtk-3-template/package.json +++ b/examples/gtk-3-template/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-3-template-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 3 example app to demonstrate how you can use .ui template XML files", "type": "module", "private": true, diff --git a/examples/gtk-3-webkit/package.json b/examples/gtk-3-webkit/package.json index cc8a78fe..a3601113 100644 --- a/examples/gtk-3-webkit/package.json +++ b/examples/gtk-3-webkit/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-3-webkit-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 3 example app to demonstrate how you can use WebKit2", "type": "module", "private": true, diff --git a/examples/gtk-4-application/package.json b/examples/gtk-4-application/package.json index 136317d7..d2b384da 100644 --- a/examples/gtk-4-application/package.json +++ b/examples/gtk-4-application/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-4-application-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 4 example app to demonstrate how you can use and extend Gtk.Application", "type": "module", "private": true, diff --git a/examples/gtk-4-custom-widget/package.json b/examples/gtk-4-custom-widget/package.json index dfa7e24c..b835a8c9 100644 --- a/examples/gtk-4-custom-widget/package.json +++ b/examples/gtk-4-custom-widget/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gjs-gtk-4-custom-widget-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "This example shows the usage of custom widgets and virtual functions in GJS", "type": "module", "private": true, diff --git a/examples/gtk-4-gettext/package.json b/examples/gtk-4-gettext/package.json index 5a054978..175feaf1 100644 --- a/examples/gtk-4-gettext/package.json +++ b/examples/gtk-4-gettext/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-4-gettext-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 3 example app that shows how you can translate strings with gettext", "type": "module", "private": true, diff --git a/examples/gtk-4-list-store/package.json b/examples/gtk-4-list-store/package.json index b93e414e..9492dad2 100644 --- a/examples/gtk-4-list-store/package.json +++ b/examples/gtk-4-list-store/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-4-list-store-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "It takes the hassle away from building Gtk4 application in Python So you can create a cool application, without all the boilerplate code", "type": "module", "private": true, diff --git a/examples/gtk-4-template-esbuild/package.json b/examples/gtk-4-template-esbuild/package.json index b5988048..43d09367 100644 --- a/examples/gtk-4-template-esbuild/package.json +++ b/examples/gtk-4-template-esbuild/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-4-template-esbuild", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 4 example app to demonstrate how you can use .ui template XML files over GJS itself", "type": "module", "private": true, diff --git a/examples/gtk-4-template-tsc/package.json b/examples/gtk-4-template-tsc/package.json index 29514f87..e1211857 100644 --- a/examples/gtk-4-template-tsc/package.json +++ b/examples/gtk-4-template-tsc/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-4-template-tsc", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 4 example app to demonstrate how you can use .ui template XML files over GJS itself", "type": "module", "private": true, diff --git a/examples/gtk-4-template-vite/package.json b/examples/gtk-4-template-vite/package.json index 7a0c5fe2..8f0537ea 100644 --- a/examples/gtk-4-template-vite/package.json +++ b/examples/gtk-4-template-vite/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/gtk-4-template-vite", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 4 example app to demonstrate how you can use .ui template XML files over the Vite bundler", "type": "module", "private": true, diff --git a/examples/run-async/package.json b/examples/run-async/package.json index 38df48aa..41d13848 100644 --- a/examples/run-async/package.json +++ b/examples/run-async/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/run-async-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 3 example app that shows how you can translate strings with gettext", "type": "module", "private": true, diff --git a/examples/soup-3-http/package.json b/examples/soup-3-http/package.json index 269113a7..44d15de3 100644 --- a/examples/soup-3-http/package.json +++ b/examples/soup-3-http/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/soup-3-http-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "GJS example showing how to build a http server/client using Soap 3", "type": "module", "private": true, diff --git a/examples/soup-3-websocket/package.json b/examples/soup-3-websocket/package.json index 296f226d..227f7528 100644 --- a/examples/soup-3-websocket/package.json +++ b/examples/soup-3-websocket/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/soup-3-websocket-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Soup 3 example app to demonstrate how you can use WebSockets", "type": "module", "private": true, diff --git a/examples/timers/package.json b/examples/timers/package.json index 5153a38e..0a31e34a 100644 --- a/examples/timers/package.json +++ b/examples/timers/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir-example/timers-example", - "version": "4.0.0-beta.10", + "version": "4.0.0-beta.12", "description": "Simple GJS Gtk 4 example app to demonstrate how you can use .ui template XML files", "type": "module", "private": true, diff --git a/package.json b/package.json index 4086f591..6fe6402f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-for-gir", - "version": "4.0.0-beta.11", + "version": "4.0.0-beta.12", "description": "Typescript .d.ts generator from GIR for gjs", "type": "module", "private": true, diff --git a/packages/cli/package.json b/packages/cli/package.json index 3635fcc8..79f884f6 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir/cli", - "version": "4.0.0-beta.11", + "version": "4.0.0-beta.12", "description": "TypeScript type definition generator for GObject introspection GIR files", "module": "lib/index.js", "main": "lib/index.js", diff --git a/packages/generator-base/package.json b/packages/generator-base/package.json index e35a2f06..f7486f26 100644 --- a/packages/generator-base/package.json +++ b/packages/generator-base/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir/generator-base", - "version": "4.0.0-beta.11", + "version": "4.0.0-beta.12", "description": "Base generator for ts-for-gir", "module": "lib/index.js", "main": "lib/index.js", diff --git a/packages/generator-html-doc/package.json b/packages/generator-html-doc/package.json index 2289eed6..d119d44f 100644 --- a/packages/generator-html-doc/package.json +++ b/packages/generator-html-doc/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir/generator-html-doc", - "version": "4.0.0-beta.11", + "version": "4.0.0-beta.12", "description": "HTML Documentation generator for ts-for-gir", "module": "lib/index.js", "main": "lib/index.js", diff --git a/packages/generator-typescript/package.json b/packages/generator-typescript/package.json index 9dba82de..3855bdb7 100644 --- a/packages/generator-typescript/package.json +++ b/packages/generator-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir/generator-typescript", - "version": "4.0.0-beta.11", + "version": "4.0.0-beta.12", "description": "TypeScript type definition generator for ts-for-gir", "module": "lib/index.js", "main": "lib/index.js", diff --git a/packages/generator-typescript/templates/gjs/cairo-1.0.d.ts b/packages/generator-typescript/templates/gjs/cairo-1.0.d.ts index cff49e75..e69de29b 100644 --- a/packages/generator-typescript/templates/gjs/cairo-1.0.d.ts +++ b/packages/generator-typescript/templates/gjs/cairo-1.0.d.ts @@ -1,9 +0,0 @@ -// TODO -// See -// - https://gitlab.gnome.org/GNOME/gjs/-/blob/master/installed-tests/js/testCairoModule.js -// - https://gitlab.gnome.org/GNOME/gjs/-/blob/master/installed-tests/js/testCairo.js -// - https://gitlab.gnome.org/GNOME/gjs/-/blob/master/doc/cairo.md - -// image_surface_create -> ImageSurface -// Context.constructor(surface: cairo.ImageSurface) -// ... diff --git a/packages/generator-typescript/templates/gjs/cairo.d.ts b/packages/generator-typescript/templates/gjs/cairo.d.ts index d2f3cfc6..06461955 100644 --- a/packages/generator-typescript/templates/gjs/cairo.d.ts +++ b/packages/generator-typescript/templates/gjs/cairo.d.ts @@ -1,11 +1,498 @@ +<%_ const Cairo = await dep.get('cairo', '1.0') _%> +<%_ const GObject = await dep.get('GObject', '2.0') _%> + <%_ if(!package){ -%> declare module 'cairo' { <% } -%> -// TODO: See ./cairo-1.0.d.ts -<%- package ? 'declare' : '' %> const Cairo: any; +// Cairo 1.0 +import type Cairo from '<%- Cairo.importPath %>'; +<%- GObject.importDef %> + +<%- package ? 'declare' : '' %> namespace giCairo { + + // Add overrides here + // See + // - https://gitlab.gnome.org/GNOME/gjs/-/blob/master/doc/cairo.md + // - https://gitlab.gnome.org/GNOME/gjs/-/blob/master/installed-tests/js/testCairoModule.js + // - https://gitlab.gnome.org/GNOME/gjs/-/blob/master/installed-tests/js/testCairo.js + // - https://gitlab.gnome.org/GNOME/gjs/-/blob/master/modules/cairo-context.cpp + + // Re-exported enums + export namespace Status { + export const $gtype: GObject.GType; + } + + enum Status { + SUCCESS, + NO_MEMORY, + INVALID_RESTORE, + INVALID_POP_GROUP, + NO_CURRENT_POINT, + INVALID_MATRIX, + INVALID_STATUS, + NULL_POINTER, + INVALID_STRING, + INVALID_PATH_DATA, + READ_ERROR, + WRITE_ERROR, + SURFACE_FINISHED, + SURFACE_TYPE_MISMATCH, + PATTERN_TYPE_MISMATCH, + INVALID_CONTENT, + INVALID_FORMAT, + INVALID_VISUAL, + FILE_NOT_FOUND, + INVALID_DASH, + INVALID_DSC_COMMENT, + INVALID_INDEX, + CLIP_NOT_REPRESENTABLE, + TEMP_FILE_ERROR, + INVALID_STRIDE, + FONT_TYPE_MISMATCH, + USER_FONT_IMMUTABLE, + USER_FONT_ERROR, + NEGATIVE_COUNT, + INVALID_CLUSTERS, + INVALID_SLANT, + INVALID_WEIGHT, + INVALID_SIZE, + USER_FONT_NOT_IMPLEMENTED, + DEVICE_TYPE_MISMATCH, + DEVICE_ERROR, + INVALID_MESH_CONSTRUCTION, + DEVICE_FINISHED, + JBIG2_GLOBAL_MISSING, + } + + export namespace Content { + export const $gtype: GObject.GType; + } + + enum Content { + COLOR, + ALPHA, + COLOR_ALPHA, + } + + export namespace Operator { + export const $gtype: GObject.GType; + } + + enum Operator { + CLEAR, + SOURCE, + OVER, + IN, + OUT, + ATOP, + DEST, + DEST_OVER, + DEST_IN, + DEST_OUT, + DEST_ATOP, + XOR, + ADD, + SATURATE, + MULTIPLY, + SCREEN, + OVERLAY, + DARKEN, + LIGHTEN, + COLOR_DODGE, + COLOR_BURN, + HARD_LIGHT, + SOFT_LIGHT, + DIFFERENCE, + EXCLUSION, + HSL_HUE, + HSL_SATURATION, + HSL_COLOR, + HSL_LUMINOSITY, + } + + export namespace Antialias { + export const $gtype: GObject.GType; + } + + enum Antialias { + DEFAULT, + NONE, + GRAY, + SUBPIXEL, + FAST, + GOOD, + BEST, + } + + export namespace FillRule { + export const $gtype: GObject.GType; + } + + enum FillRule { + WINDING, + EVEN_ODD, + } + + export namespace LineCap { + export const $gtype: GObject.GType; + } + + enum LineCap { + BUTT, + ROUND, + SQUARE, + } + + export namespace LineJoin { + export const $gtype: GObject.GType; + } + + enum LineJoin { + MITER, + ROUND, + BEVEL, + } + + export namespace TextClusterFlags { + export const $gtype: GObject.GType; + } + + enum TextClusterFlags { + BACKWARD, + } + + export namespace FontSlant { + export const $gtype: GObject.GType; + } + + enum FontSlant { + NORMAL, + ITALIC, + OBLIQUE, + } + + export namespace FontWeight { + export const $gtype: GObject.GType; + } + + enum FontWeight { + NORMAL, + BOLD, + } + + export namespace SubpixelOrder { + export const $gtype: GObject.GType; + } + + enum SubpixelOrder { + DEFAULT, + RGB, + BGR, + VRGB, + VBGR, + } + + export namespace HintStyle { + export const $gtype: GObject.GType; + } + + enum HintStyle { + DEFAULT, + NONE, + SLIGHT, + MEDIUM, + FULL, + } + + export namespace HintMetrics { + export const $gtype: GObject.GType; + } + + enum HintMetrics { + DEFAULT, + OFF, + ON, + } + + export namespace FontType { + export const $gtype: GObject.GType; + } + + enum FontType { + TOY, + FT, + WIN32, + QUARTZ, + USER, + } + + export namespace PathDataType { + export const $gtype: GObject.GType; + } + + enum PathDataType { + MOVE_TO, + LINE_TO, + CURVE_TO, + CLOSE_PATH, + } + + export namespace DeviceType { + export const $gtype: GObject.GType; + } + + enum DeviceType { + DRM, + GL, + SCRIPT, + XCB, + XLIB, + XML, + COGL, + WIN32, + INVALID, + } + + export namespace SurfaceType { + export const $gtype: GObject.GType; + } + + enum SurfaceType { + IMAGE, + PDF, + PS, + XLIB, + XCB, + GLITZ, + QUARTZ, + WIN32, + BEOS, + DIRECTFB, + SVG, + OS2, + WIN32_PRINTING, + QUARTZ_IMAGE, + SCRIPT, + QT, + RECORDING, + VG, + GL, + DRM, + TEE, + XML, + SKIA, + SUBSURFACE, + COGL, + } + + export namespace Format { + export const $gtype: GObject.GType; + } + + enum Format { + INVALID, + ARGB32, + RGB24, + A8, + A1, + RGB16_565, + RGB30, + } + + export namespace PatternType { + export const $gtype: GObject.GType; + } + + enum PatternType { + SOLID, + SURFACE, + LINEAR, + RADIAL, + MESH, + RASTER_SOURCE, + } + + export namespace Extend { + export const $gtype: GObject.GType; + } + + enum Extend { + NONE, + REPEAT, + REFLECT, + PAD, + } + + export namespace Filter { + export const $gtype: GObject.GType; + } + + enum Filter { + FAST, + GOOD, + BEST, + NEAREST, + BILINEAR, + GAUSSIAN, + } + + export namespace RegionOverlap { + export const $gtype: GObject.GType; + } + + enum RegionOverlap { + IN, + OUT, + PART, + } + + export class Context extends Cairo.Context { + constructor(surface: Surface); + + arc(xc: number, yc: number, radius: number, angle1: number, angle2: number): void; + arcNegative(xc: number, yc: number, radius: number, angle1: number, angle2: number): void; + curveTo(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void; + clip(): void; + clipPreserve(): void; + clipExtents(): [number, number, number, number]; + closePath(): void; + copyPage(): void; + deviceToUser(x: number, y: number): [number, number]; + deviceToUserDistance(x: number, y: number): [number, number]; + fill(): void; + fillPreserve(): void; + fillExtents(): [number, number, number, number]; + getAntialias(): Antialias; + getCurrentPoint(): [number, number]; + getDashCount(): number; + getFillRule(): FillRule; + getLineCap(): LineCap; + getLineJoin(): LineJoin; + getLineWidth(): number; + getMiterLimit(): number; + getOperator(): Operator; + getTolerance(): number; + hasCurrentPoint(): boolean; + identityMatrix(): void; + inFill(x: number, y: number): boolean; + inStroke(x: number, y: number): boolean; + lineTo(x: number, y: number): void; + moveTo(x: number, y: number): void; + newPath(): void; + newSubPath(): void; + paint(): void; + paintWithAlpha(alpha: number): void; + pathExtents(): [number, number, number, number]; + popGroup(): Pattern; + popGroupToSource(): void; + pushGroup(): void; + pushGroupWithContent(content: Content): void; + rectangle(x: number, y: number, width: number, height: number): void; + relCurveTo(dx1: number, dy1: number, dx2: number, dy2: number, dx3: number, dy3: number): void; + relLineTo(dx: number, dy: number): void; + relMoveTo(dx: number, dy: number): void; + resetClip(): void; + restore(): void; + rotate(angle: number): void; + save(): void; + scale(sx: number, sy: number): void; + selectFontFace(family: string, slant: number, weight: number): void; + setAntialias(antialias: Antialias): void; + setDash(dashes: number[], offset: number): void; + setFontSize(size: number): void; + setFillRule(fillRule: FillRule): void; + setLineCap(lineCap: LineCap): void; + setLineJoin(lineJoin: LineJoin): void; + setLineWidth(width: number): void; + setMiterLimit(limit: number): void; + setOperator(op: Operator): void; + setSource(pattern: Pattern): void; + setSourceRGB(red: number, green: number, blue: number): void; + setSourceRGBA(red: number, green: number, blue: number, alpha: number): void; + setSourceSurface(surface: Surface, x: number, y: number): void; + setTolerance(tolerance: number): void; + showPage(): void; + showText(utf8: string): void; + stroke(): void; + strokePreserve(): void; + strokeExtents(): [number, number, number, number]; + textExtents(utf8: string): TextExtents; + translate(tx: number, ty: number): void; + userToDevice(x: number, y: number): [number, number]; + userToDeviceDistance(x: number, y: number): [number, number]; + } + + export abstract class Surface extends Cairo.Surface { + // TODO + } + + export class ImageSurface extends Surface { + constructor(format: Format, width: number, height: number); + + static createFromPNG(filename: string): ImageSurface; + + // TODO + } + + export class PDFSurface extends Surface { + constructor(filename: string, width: number, height: number); + + // TODO + } + + export class PSSurface extends Surface { + constructor(filename: string, width: number, height: number); + + // TODO + } + + export class SVGSurface extends Surface { + constructor(filename: string, width: number, height: number); + + // TODO + } + + export class Pattern extends Cairo.Pattern { + // TODO + } + + export class Gradient extends Pattern { + // TODO + } + + export class LinearGradient extends Gradient { + // TODO + } + + export class RadialGradient extends Gradient { + // TODO + } + + export class SurfacePattern extends Pattern { + // TODO + } + + export class SolidPattern extends Pattern { + // TODO + } + + export class Path extends Cairo.Path { + // TODO + } + + export interface TextExtents { + xBearing: number; + yBearing: number; + width: number; + height: number; + xAdvance: number; + yAdvance: number; + } + +} -export default Cairo; +export default giCairo; <%_ if(!package){ -%> } diff --git a/packages/lib/package.json b/packages/lib/package.json index 933699fd..a3abf65a 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -1,6 +1,6 @@ { "name": "@ts-for-gir/lib", - "version": "4.0.0-beta.11", + "version": "4.0.0-beta.12", "description": "Typescript .d.ts generator from GIR for gjs", "module": "lib/index.js", "main": "lib/index.js", diff --git a/packages/lib/src/dependency-manager.ts b/packages/lib/src/dependency-manager.ts index 85dedb0e..e118be68 100644 --- a/packages/lib/src/dependency-manager.ts +++ b/packages/lib/src/dependency-manager.ts @@ -105,7 +105,12 @@ export class DependencyManager extends GirNSRegistry { * @returns */ async core(): Promise { - return [await this.get('GObject', '2.0'), await this.get('GLib', '2.0'), await this.get('Gio', '2.0')] + return [ + await this.get('GObject', '2.0'), + await this.get('GLib', '2.0'), + await this.get('Gio', '2.0'), + await this.get('Cairo', '1.0'), + ] } createImportProperties(namespace: string, packageName: string, version: string) { diff --git a/types b/types index 88ef9dae..1e5bc476 160000 --- a/types +++ b/types @@ -1 +1 @@ -Subproject commit 88ef9dae197ef610481608dd1910264c3b30a253 +Subproject commit 1e5bc476433dfde1508502957a16727906fab6d0 diff --git a/yarn.lock b/yarn.lock index fa73f837..bdc2a6ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4047,6 +4047,7 @@ __metadata: version: 0.0.0-use.local resolution: "@girs/gjs@workspace:types/gjs" dependencies: + "@girs/cairo-1.0": "workspace:^" "@girs/gio-2.0": "workspace:^" "@girs/glib-2.0": "workspace:^" "@girs/gobject-2.0": "workspace:^" @@ -5793,7 +5794,7 @@ __metadata: languageName: unknown linkType: soft -"@girs/gtkclutter-1.0@workspace:types/gtkclutter-1.0": +"@girs/gtkclutter-1.0@workspace:^, @girs/gtkclutter-1.0@workspace:types/gtkclutter-1.0": version: 0.0.0-use.local resolution: "@girs/gtkclutter-1.0@workspace:types/gtkclutter-1.0" dependencies: @@ -12325,6 +12326,15 @@ __metadata: languageName: unknown linkType: soft +"@ts-for-gir-example/cairo-surfaces-tsc@workspace:examples/cairo-surfaces-tsc": + version: 0.0.0-use.local + resolution: "@ts-for-gir-example/cairo-surfaces-tsc@workspace:examples/cairo-surfaces-tsc" + dependencies: + "@girs/gjs": "workspace:^" + typescript: "npm:^5.5.3" + languageName: unknown + linkType: soft + "@ts-for-gir-example/gio-2-cat-example@workspace:examples/gio-2-cat": version: 0.0.0-use.local resolution: "@ts-for-gir-example/gio-2-cat-example@workspace:examples/gio-2-cat" @@ -12443,6 +12453,21 @@ __metadata: languageName: unknown linkType: soft +"@ts-for-gir-example/gtk-3-clutter-tsc@workspace:examples/gtk-3-clutter-tsc": + version: 0.0.0-use.local + resolution: "@ts-for-gir-example/gtk-3-clutter-tsc@workspace:examples/gtk-3-clutter-tsc" + dependencies: + "@girs/clutter-1.0": "workspace:^" + "@girs/gdk-3.0": "workspace:^" + "@girs/gio-2.0": "workspace:^" + "@girs/gjs": "workspace:^" + "@girs/glib-2.0": "workspace:^" + "@girs/gtk-3.0": "workspace:^" + "@girs/gtkclutter-1.0": "workspace:^" + typescript: "npm:^5.5.3" + languageName: unknown + linkType: soft + "@ts-for-gir-example/gtk-3-editor-example@workspace:examples/gtk-3-editor": version: 0.0.0-use.local resolution: "@ts-for-gir-example/gtk-3-editor-example@workspace:examples/gtk-3-editor"