Skip to content

Commit 4dc6078

Browse files
committed
Getting around the reflect construct.
1 parent 5e18fc5 commit 4dc6078

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

lib/svg_sigs.mli

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module type T = sig
7878
*)
7979
type 'a wrap = 'a Xml.W.t
8080

81-
(** [list_wrap] is a containre for list of elements.
81+
(** [list_wrap] is a container for list of elements.
8282
8383
In most cases, ['a list_wrap = 'a list]. For [R] modules (in eliom or js_of_ocaml),
8484
It will be {!ReactiveData.RList.t}.
@@ -488,7 +488,7 @@ module type T = sig
488488
val a_animation_fill : [< | `Freeze | `Remove ] wrap -> [> | `Fill_Animation ] attrib
489489
[@@reflect.attribute "fill" ["animate"]]
490490

491-
val a_fill_opacity : number wrap -> [> | `Fill_opacity ] attrib
491+
val a_fill_opacity : opacity wrap -> [> | `Fill_opacity ] attrib
492492

493493
val a_fill_rule : fill_rule wrap -> [> | `Fill_rule ] attrib
494494

@@ -635,11 +635,11 @@ module type T = sig
635635
| `Text_after_edge | `Text_before_edge | `Inherit ] wrap ->
636636
[> | `Dominant_Baseline ] attrib
637637

638-
val a_opacity : number wrap -> [> | `Opacity ] attrib
638+
val a_opacity : opacity wrap -> [> | `Opacity ] attrib
639639

640640
val a_stop_color : color wrap -> [> | `Stop_Color ] attrib
641641

642-
val a_stop_opacity : number wrap -> [> | `Stop_Opacity ] attrib
642+
val a_stop_opacity : opacity wrap -> [> | `Stop_Opacity ] attrib
643643

644644
val a_stroke : paint wrap -> [> | `Stroke ] attrib
645645

@@ -658,7 +658,7 @@ module type T = sig
658658

659659
val a_stroke_dashoffset : Unit.length wrap -> [> `Stroke_Dashoffset ] attrib
660660

661-
val a_stroke_opacity : float wrap -> [> `Stroke_Opacity ] attrib
661+
val a_stroke_opacity : opacity wrap -> [> `Stroke_Opacity ] attrib
662662

663663
(** {2 Events}
664664
@@ -1117,7 +1117,7 @@ module type Wrapped_functions = sig
11171117

11181118
val string_of_paint : ([< Svg_types.paint], string) Xml.W.ft
11191119

1120-
val string_of_opacity : (float, string) Xml.W.ft
1120+
val string_of_opacity : (opacity, string) Xml.W.ft
11211121

11221122
val string_of_fill_rule : ([< Svg_types.fill_rule], string) Xml.W.ft
11231123

lib/svg_types.mli

+2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ type strings = string list
279279
type color = string
280280
type icccolor = string
281281

282+
type opacity = float
283+
282284
type paint_whitout_icc =
283285
[ `None | `CurrentColor
284286
| `Color of (color * icccolor option)

syntax/attribute_value.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ let paint ?separated_by:_ ?default:_ loc name s =
484484
`Icc ([%e iri], Some [%e paint_without_icc loc name remainder])]
485485
end [@metaloc loc]
486486

487-
let fill_opacity =
487+
let opacity =
488488
let bad_form name loc =
489489
Common.error loc "Value of %s must be a number or percentage" name in
490490

syntax/attribute_value.mli

+4-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ val paint : parser
198198
{:{https://www.w3.org/TR/SVG/painting.html#SpecifyingPaint} Specifying
199199
paint}. *)
200200

201-
val fill_opacity : parser
202-
(** Parses an SVG fill-opacity value, converting it into a number between 0. and 1.
201+
val opacity : parser
202+
(** Parses an SVG fill-opacity value (either a percentage or a number),
203+
converting it into a number between 0. and 1.
204+
This parser is also used in other places expecting opacity.
203205
204206
@see <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-opacity>
205207
*)

syntax/reflect/reflect.ml

+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ let rec to_attribute_parser lang name ~loc = function
154154
| [[%type: iri]]
155155
| [[%type: color]] -> [%expr string]
156156

157+
| [[%type: opacity]] -> [%expr opacity]
158+
157159
| [[%type: nmtoken]; [%type: text wrap]] -> [%expr wrap string]
158160
| [[%type: string]; [%type: string wrap]] -> [%expr wrap string]
159161
| [[%type: string]; [%type: string list wrap]] -> [%expr wrap (spaces string)]

test/test_jsx.re

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,12 @@ let svg = (
333333
),
334334
(
335335
"fill_opacity float, circle",
336-
[<circle cx=1 cy=2 r=3 fill-opacity=0.5 />],
336+
[<circle cx=1 cy=2 r=3 fill_opacity=0.5 />],
337337
[circle(~a=[a_cx (1., None); a_cy (2., None); a_r (3., None); a_fill_opacity 0.5], [])],
338338
),
339339
(
340340
"fill_opacity percentage, rect",
341-
[<rect x=1 y='2' width=3 height='4' fill-opacity='50%' />],
341+
[<rect x=1 y='2' width=3 height='4' fill_opacity='50%' />],
342342
[rect(~a=[a_cx (1., None); a_cy (2., None); a_width (3., None); a_height (4., None); a_fill_opacity 0.5], [])],
343343
),
344344
(

0 commit comments

Comments
 (0)