Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

melange 5: port @mel.send.pipe to @mel.send + @mel.this #23

Merged
merged 4 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(authors "Cheng Lou <[email protected]>")

(maintainers
"Javier Ch\195\161varri <[email protected]>"
"Javier Chávarri <[email protected]>"
"David Sancho <[email protected]>")

(homepage "https://github.com/melange-community/melange-webapi")
Expand All @@ -28,7 +28,7 @@
(depends
ocaml
(melange
(>= "2.0.0"))
(>= "5.0.1"))
melange-fetch
(reason
(>= "3.10"))
Expand Down
14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
forAllSystems = f: nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system:
let
pkgs = nixpkgs.legacyPackages.${system}.extend (self: super: {
ocamlPackages = super.ocaml-ng.ocamlPackages_5_2;
ocamlPackages = super.ocaml-ng.ocamlPackages_5_3;
});
in
f pkgs);
Expand Down
2 changes: 1 addition & 1 deletion melange-webapi.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bug-reports: "https://github.com/melange-community/melange-webapi/issues"
depends: [
"dune" {>= "3.8"}
"ocaml"
"melange" {>= "2.0.0"}
"melange" {>= "5.0.1"}
"melange-fetch"
"reason" {>= "3.10"}
"ocaml-lsp-server" {with-test}
Expand Down
16 changes: 8 additions & 8 deletions scripts/eventTemplate.re
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

let typ = Node.Process.argv[2];
let name = Node.Process.argv[3];
let lname = name |> Js.String.toLowerCase;

{j|
[@mel.send.pipe : T.t] external add$(name)EventListener : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit) => unit = "addEventListener";
[@mel.send.pipe : T.t] external add$(name)EventListenerWithOptions : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, {. "capture": bool, "once": bool, "passive": bool}) => unit = "addEventListener"; /* not widely supported */
[@mel.send.pipe : T.t] external add$(name)EventListenerUseCapture : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, [@mel.as {json|true|json}] _) => unit = "addEventListener";
[@mel.send.pipe : T.t] external remove$(name)EventListener : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit) => unit = "removeEventListener";
[@mel.send.pipe : T.t] external remove$(name)EventListenerWithOptions : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, {. "capture": bool, "passive": bool}) => unit = "removeEventListener"; /* not widely supported */
[@mel.send.pipe : T.t] external remove$(name)EventListenerUseCapture : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, [@mel.as {json|true|json}] _) => unit = "removeEventListener";
|j} |> Js.log;
[@mel.send] external add$(name)EventListener : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, [@mel.this] T.t) => unit = "addEventListener";
[@mel.send] external add$(name)EventListenerWithOptions : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, {. "capture": bool, "once": bool, "passive": bool}, [@mel.this] T.t) => unit = "addEventListener"; /* not widely supported */
[@mel.send] external add$(name)EventListenerUseCapture : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, [@mel.as {json|true|json}] _, [@mel.this] T.t) => unit = "addEventListener";
[@mel.send] external remove$(name)EventListener : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, [@mel.this] T.t) => unit = "removeEventListener";
[@mel.send] external remove$(name)EventListenerWithOptions : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, {. "capture": bool, "passive": bool}, [@mel.this] T.t) => unit = "removeEventListener"; /* not widely supported */
[@mel.send] external remove$(name)EventListenerUseCapture : ([@mel.as "$(lname)"] _, Dom.$(typ) => unit, [@mel.as {json|true|json}] _, [@mel.this] T.t) => unit = "removeEventListener";
|j}
|> Js.log;
120 changes: 73 additions & 47 deletions src/Webapi/Canvas/Webapi__Canvas__Canvas2d.re
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,39 @@ type style(_) =
| Pattern: style(pattern);

/* 2d Canvas API, following https://simon.html5.org/dump/html5-canvas-cheat-sheet.html */
[@mel.send.pipe: t] external save: unit = "save";
[@mel.send.pipe: t] external restore: unit = "restore";
[@mel.send] external save: ([@mel.this] t) => unit = "save";
[@mel.send] external restore: ([@mel.this] t) => unit = "restore";

/* Transformation */
[@mel.send.pipe: t] external scale: (~x: float, ~y: float) => unit = "scale";
[@mel.send.pipe: t] external rotate: float => unit = "rotate";
[@mel.send.pipe: t]
external translate: (~x: float, ~y: float) => unit = "translate";
[@mel.send.pipe: t]
[@mel.send]
external scale: (~x: float, ~y: float, [@mel.this] t) => unit = "scale";
[@mel.send] external rotate: (float, [@mel.this] t) => unit = "rotate";
[@mel.send]
external translate: (~x: float, ~y: float, [@mel.this] t) => unit =
"translate";
[@mel.send]
external transform:
(
~m11: float,
~m12: float,
~m21: float,
~m22: float,
~dx: float,
~dy: float
~dy: float,
[@mel.this] t
) =>
unit =
"transform";
[@mel.send.pipe: t]
[@mel.send]
external setTransform:
(
~m11: float,
~m12: float,
~m21: float,
~m22: float,
~dx: float,
~dy: float
~dy: float,
[@mel.this] t
) =>
unit =
"setTransform";
Expand Down Expand Up @@ -177,17 +181,26 @@ let strokeStyle = (ctx: t) => ctx |> strokeStyle |> reifyStyle;
[@mel.set] external shadowColor: (t, string) => unit = "shadowColor";

/* Gradients */
[@mel.send.pipe: t]
[@mel.send]
external createLinearGradient:
(~x0: float, ~y0: float, ~x1: float, ~y1: float) => gradient =
(~x0: float, ~y0: float, ~x1: float, ~y1: float, [@mel.this] t) => gradient =
"createLinearGradient";
[@mel.send.pipe: t]
[@mel.send]
external createRadialGradient:
(~x0: float, ~y0: float, ~x1: float, ~y1: float, ~r0: float, ~r1: float) =>
(
~x0: float,
~y0: float,
~x1: float,
~y1: float,
~r0: float,
~r1: float,
[@mel.this] t
) =>
gradient =
"createRadialGradient";
[@mel.send.pipe: gradient]
external addColorStop: (float, string) => unit = "addColorStop";
[@mel.send]
external addColorStop: (float, string, [@mel.this] gradient) => unit =
"addColorStop";

external createPattern:
(
Expand All @@ -204,73 +217,86 @@ external createPattern:
"createPattern";

/* Paths */
[@mel.send.pipe: t] external beginPath: unit = "beginPath";
[@mel.send.pipe: t] external closePath: unit = "closePath";
[@mel.send.pipe: t] external fill: unit = "fill";
[@mel.send.pipe: t] external stroke: unit = "stroke";
[@mel.send.pipe: t] external clip: unit = "clip";
[@mel.send.pipe: t] external moveTo: (~x: float, ~y: float) => unit = "moveTo";
[@mel.send.pipe: t] external lineTo: (~x: float, ~y: float) => unit = "lineTo";
[@mel.send.pipe: t]
[@mel.send] external beginPath: ([@mel.this] t) => unit = "beginPath";
[@mel.send] external closePath: ([@mel.this] t) => unit = "closePath";
[@mel.send] external fill: ([@mel.this] t) => unit = "fill";
[@mel.send] external stroke: ([@mel.this] t) => unit = "stroke";
[@mel.send] external clip: ([@mel.this] t) => unit = "clip";
[@mel.send]
external moveTo: (~x: float, ~y: float, [@mel.this] t) => unit = "moveTo";
[@mel.send]
external lineTo: (~x: float, ~y: float, [@mel.this] t) => unit = "lineTo";
[@mel.send]
external quadraticCurveTo:
(~cp1x: float, ~cp1y: float, ~x: float, ~y: float) => unit =
(~cp1x: float, ~cp1y: float, ~x: float, ~y: float, [@mel.this] t) => unit =
"quadraticCurveTo";
[@mel.send.pipe: t]
[@mel.send]
external bezierCurveTo:
(
~cp1x: float,
~cp1y: float,
~cp2x: float,
~cp2y: float,
~x: float,
~y: float
~y: float,
[@mel.this] t
) =>
unit =
"bezierCurveTo";
[@mel.send.pipe: t]
[@mel.send]
external arcTo:
(~x1: float, ~y1: float, ~x2: float, ~y2: float, ~r: float) => unit =
(~x1: float, ~y1: float, ~x2: float, ~y2: float, ~r: float, [@mel.this] t) =>
unit =
"arcTo";
[@mel.send.pipe: t]
[@mel.send]
external arc:
(
~x: float,
~y: float,
~r: float,
~startAngle: float,
~endAngle: float,
~anticw: bool
~anticw: bool,
[@mel.this] t
) =>
unit =
"arc";
[@mel.send.pipe: t]
external rect: (~x: float, ~y: float, ~w: float, ~h: float) => unit = "rect";
[@mel.send.pipe: t]
external isPointInPath: (~x: float, ~y: float) => bool = "isPointInPath";
[@mel.send]
external rect:
(~x: float, ~y: float, ~w: float, ~h: float, [@mel.this] t) => unit =
"rect";
[@mel.send]
external isPointInPath: (~x: float, ~y: float, [@mel.this] t) => bool =
"isPointInPath";

/* Text */
[@mel.set] external font: (t, string) => unit = "font";
[@mel.set] external textAlign: (t, string) => unit = "textAlign";
[@mel.set] external textBaseline: (t, string) => unit = "textBaseline";
[@mel.send.pipe: t]
external fillText: (string, ~x: float, ~y: float, ~maxWidth: float=?) => unit =
[@mel.send]
external fillText:
(string, ~x: float, ~y: float, ~maxWidth: float=?, [@mel.this] t) => unit =
"fillText";
[@mel.send.pipe: t]
external strokeText: (string, ~x: float, ~y: float, ~maxWidth: float=?) => unit =
[@mel.send]
external strokeText:
(string, ~x: float, ~y: float, ~maxWidth: float=?, [@mel.this] t) => unit =
"strokeText";
[@mel.send.pipe: t]
external measureText: string => measureText = "measureText";
[@mel.send]
external measureText: (string, [@mel.this] t) => measureText = "measureText";
[@mel.get] external width: measureText => float = "width";

/* Rectangles */
[@mel.send.pipe: t]
external fillRect: (~x: float, ~y: float, ~w: float, ~h: float) => unit =
[@mel.send]
external fillRect:
(~x: float, ~y: float, ~w: float, ~h: float, [@mel.this] t) => unit =
"fillRect";
[@mel.send.pipe: t]
external strokeRect: (~x: float, ~y: float, ~w: float, ~h: float) => unit =
[@mel.send]
external strokeRect:
(~x: float, ~y: float, ~w: float, ~h: float, [@mel.this] t) => unit =
"strokeRect";
[@mel.send.pipe: t]
external clearRect: (~x: float, ~y: float, ~w: float, ~h: float) => unit =
[@mel.send]
external clearRect:
(~x: float, ~y: float, ~w: float, ~h: float, [@mel.this] t) => unit =
"clearRect";

[@mel.send]
Expand Down
23 changes: 14 additions & 9 deletions src/Webapi/Dom/Webapi__Dom__CharacterData.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ module Impl = (T: {
[@mel.get] external data: T.t => string = "data";
[@mel.get] external length: T.t => int = "length";

[@mel.send.pipe: T.t]
external substringData: (~offset: int, ~count: int) => string =
[@mel.send]
external substringData:
(~offset: int, ~count: int, [@mel.this] T.t) => string =
"substringData";
[@mel.send.pipe: T.t] external appendData: string => unit = "appendData";
[@mel.send.pipe: T.t]
external insertData: (~offset: int, string) => unit = "insertData";
[@mel.send.pipe: T.t]
external deleteData: (~offset: int, ~count: int) => unit = "deleteData";
[@mel.send.pipe: T.t]
external replaceData: (~offset: int, ~count: int, string) => unit =
[@mel.send]
external appendData: (string, [@mel.this] T.t) => unit = "appendData";
[@mel.send]
external insertData: (~offset: int, string, [@mel.this] T.t) => unit =
"insertData";
[@mel.send]
external deleteData: (~offset: int, ~count: int, [@mel.this] T.t) => unit =
"deleteData";
[@mel.send]
external replaceData:
(~offset: int, ~count: int, string, [@mel.this] T.t) => unit =
"replaceData";
};

Expand Down
2 changes: 1 addition & 1 deletion src/Webapi/Dom/Webapi__Dom__ChildNode.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
module Impl = (T: {
type t;
}) => {
[@mel.send.pipe: T.t] external remove: unit = "remove";
[@mel.send] external remove: ([@mel.this] T.t) => unit = "remove";
};
23 changes: 14 additions & 9 deletions src/Webapi/Dom/Webapi__Dom__CssStyleDeclaration.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ type cssRule; /* TODO: Move to Webapi__Dom */
[@mel.get] external length: t => int = "length";
[@mel.get] external parentRule: t => cssRule = "parentRule";

[@mel.send.pipe: t]
external getPropertyPriority: string => string = "getPropertyPriority";
[@mel.send.pipe: t]
external getPropertyValue: string => string = "getPropertyValue";
[@mel.send.pipe: t] external item: int => string = "item";
[@mel.send.pipe: t]
external removeProperty: string => string = "removeProperty";
[@mel.send.pipe: t]
external setProperty: (string, string, string) => unit = "setProperty" /*[@@mel.send.pipe : t] external setPropertyValue : (string, string) => unit = "setPropertyValue";*/; /* not mentioned by MDN and not implemented by chrome, but in the CSSOM spec: https://drafts.csswg.org/cssom/#the-cssstyledeclaration-interface */
[@mel.send]
external getPropertyPriority: (string, [@mel.this] t) => string =
"getPropertyPriority";
[@mel.send]
external getPropertyValue: (string, [@mel.this] t) => string =
"getPropertyValue";
[@mel.send] external item: (int, [@mel.this] t) => string = "item";
[@mel.send]
external removeProperty: (string, [@mel.this] t) => string = "removeProperty";
[@mel.send]
external setProperty: (string, string, string, [@mel.this] t) => unit =
"setProperty" /* [@mel.send] external setPropertyValue : (string, string) => ([@mel.this] t) => unit = "setPropertyValue";*/; /* not mentioned by MDN and not implemented by chrome, but in the CSSOM spec: https://drafts.csswg.org/cssom/#the-cssstyledeclaration-interface */

/* CSS2Properties */

[@mel.get] external azimuth: t => string = "azimuth";
[@mel.get] external background: t => string = "background";
[@mel.get] external backgroundAttachment: t => string = "backgroundAttachment";
Expand Down
Loading