1- open Ppxlib ;
2-
1+ module Location = Ppxlib . Location ;
2+ module Parsetree = Ppxlib . Parsetree ;
33module Builder = Ppxlib . Ast_builder . Default ;
44
55module Standard = Css_property_parser . Standard ;
@@ -79,7 +79,8 @@ let render_option = (~loc, f) =>
7979 | Some (v ) => [% expr Some ([% e f(~loc, v)])]
8080 | None => [% expr None ];
8181
82- let list_to_longident = vars => vars |> String . concat("." ) |> Longident . parse;
82+ let list_to_longident = vars =>
83+ vars |> String . concat("." ) |> Ppxlib . Longident . parse;
8384
8485let render_variable = (~loc, name) =>
8586 list_to_longident(name) |> txt(~loc) |> Builder . pexp_ident(~loc);
@@ -1303,7 +1304,7 @@ let render_box_shadow = (~loc, shadow) => {
13031304 );
13041305
13051306 let args =
1306- [
1307+ Ppxlib . Asttypes . [
13071308 (Labelled ("x" ), Some (x)),
13081309 (Labelled ("y" ), Some (y)),
13091310 (Labelled ("blur" ), blur),
@@ -2909,7 +2910,7 @@ let render_text_shadow = (~loc, shadow) => {
29092910 };
29102911
29112912 let args =
2912- [
2913+ Ppxlib . Asttypes . [
29132914 (Labelled ("x" ), Some (render_length_interp(~loc, x))),
29142915 (Labelled ("y" ), Some (render_length_interp(~loc, y))),
29152916 (Labelled ("blur" ), Option . map(render_length_interp(~loc), blur)),
@@ -5199,13 +5200,13 @@ let filter =
51995200 monomorphic(
52005201 Property_parser . property_filter,
52015202 (~loc) => [% expr CSS . filter],
5202- (~loc, value) =>
5203+ (~loc, value) => {
52035204 switch (value) {
52045205 | ` None => [% expr [| ` none |] ]
52055206 | ` Interpolation (v ) => render_variable(~loc, v)
52065207 | ` Filter_function_list (ffl ) => render_filter_function_list(~loc, ffl)
5207- | ` _ms_filter_function_list ( _ ) => raise ( Unsupported_feature )
5208- },
5208+ }
5209+ },
52095210 );
52105211
52115212let backdrop_filter =
@@ -5474,20 +5475,21 @@ let render_quote = (~loc, quote: Types.quote) => {
54745475
54755476let render_content_string = (~loc, str) => {
54765477 let length = String . length(str);
5478+ let get = String . get;
54775479 let str =
54785480 if (length == 0 ) {
54795481 [% expr { js | ''| js } ];
5480- } else if (length == 1 && str. [0] == '"') {
5482+ } else if (length == 1 && get( str, 0 ) == '"' ) {
54815483 [% expr { js | '"'| js } ];
5482- } else if (length == 1 && str. [0] == ' ') {
5484+ } else if (length == 1 && get( str, 0 ) == ' ' ) {
54835485 [% expr { js | ' '| js } ];
5484- } else if (length == 1 && str. [0] == '\'') {
5486+ } else if (length == 1 && get( str, 0 ) == '\' ') {
54855487 [% expr { js | "'"| js } ];
5486- } else if (length == 2 && str. [0] == '"' && str. [1] == '"') {
5488+ } else if (length == 2 && get( str, 0 ) == '"' && get( str, 1 ) == '"' ) {
54875489 [% expr { js | ""| js } ];
54885490 } else {
5489- let first = str. [0] ;
5490- let last = str. [ length - 1 ] ;
5491+ let first = get( str, 0 ) ;
5492+ let last = get( str, length - 1 ) ;
54915493 switch (first, last) {
54925494 | ('\' ', '\' ') => [% expr [% e render_string(~loc, str)]]
54935495 | ('"' , '"' ) => [% expr [% e render_string(~loc, str)]]
@@ -5497,6 +5499,127 @@ let render_content_string = (~loc, str) => {
54975499 [% expr ` text ([% e str])];
54985500};
54995501
5502+ let render_attr_name = (~loc, attr_name: Types . attr_name ) => {
5503+ switch (attr_name) {
5504+ | (Some ((Some (label ), _ )), _label ) => [% expr
5505+ [% e render_string(~loc, label)]
5506+ ]
5507+ | (Some ((None , _ )), label ) => [% expr [% e render_string(~loc, label)]]
5508+ | (None , label ) => [% expr [% e render_string(~loc, label)]]
5509+ };
5510+ };
5511+
5512+ let render_attr_unit = (~loc, attr_unit: Types . attr_unit ) => {
5513+ switch (attr_unit) {
5514+ | ` Percent => [% expr [% e render_string(~loc, "% " )]]
5515+ | ` Em => [% expr [% e render_string(~loc, "em" )]]
5516+ | ` Vmin => [% expr [% e render_string(~loc, "vmin" )]]
5517+ | ` In => [% expr [% e render_string(~loc, "in" )]]
5518+ | ` Vw => [% expr [% e render_string(~loc, "vw" )]]
5519+ | ` Mm => [% expr [% e render_string(~loc, "mm" )]]
5520+ | ` Deg => [% expr [% e render_string(~loc, "deg" )]]
5521+ | ` Cm => [% expr [% e render_string(~loc, "cm" )]]
5522+ | ` Grad => [% expr [% e render_string(~loc, "grad" )]]
5523+ | ` Px => [% expr [% e render_string(~loc, "px" )]]
5524+ | ` KHz => [% expr [% e render_string(~loc, "kHz" )]]
5525+ | ` Ex => [% expr [% e render_string(~loc, "ex" )]]
5526+ | ` Rad => [% expr [% e render_string(~loc, "rad" )]]
5527+ | ` Ch => [% expr [% e render_string(~loc, "ch" )]]
5528+ | ` Rem => [% expr [% e render_string(~loc, "rem" )]]
5529+ | ` Pt => [% expr [% e render_string(~loc, "pt" )]]
5530+ | ` Hz => [% expr [% e render_string(~loc, "Hz" )]]
5531+ | ` Pc => [% expr [% e render_string(~loc, "pc" )]]
5532+ | ` Turn => [% expr [% e render_string(~loc, "turn" )]]
5533+ | ` S => [% expr [% e render_string(~loc, "s" )]]
5534+ | ` Vmax => [% expr [% e render_string(~loc, "vmax" )]]
5535+ | ` Ms => [% expr [% e render_string(~loc, "ms" )]]
5536+ | ` Vh => [% expr [% e render_string(~loc, "vh" )]]
5537+ };
5538+ };
5539+
5540+ let render_attr_type = (~loc, attr_type: Types . attr_type ) => {
5541+ switch (attr_type) {
5542+ | ` Raw_string => [% expr [% e render_string(~loc, "raw-string" )]]
5543+ | ` Attr_unit (attr_unit ) => [% expr [% e render_attr_unit(~loc, attr_unit)]]
5544+ };
5545+ };
5546+
5547+ let render_function_attr =
5548+ (~loc, attr_name: Types . attr_name , attr_type: option (Types . attr_type )) => {
5549+ switch (attr_type) {
5550+ | Some (attr_type ) => [% expr
5551+ ` attrWithType ((
5552+ [% e render_attr_name(~loc, attr_name)],
5553+ [% e render_attr_type(~loc, attr_type)],
5554+ ))
5555+ ]
5556+ | None => [% expr ` attr ([% e render_attr_name(~loc, attr_name)])]
5557+ };
5558+ };
5559+
5560+ let render_symbols_type = (~loc, symbols_type: Types . symbols_type ) => {
5561+ switch (symbols_type) {
5562+ | ` Cyclic => [% expr ` cyclic ]
5563+ | ` Numeric => [% expr ` numeric ]
5564+ | ` Alphabetic => [% expr ` alphabetic ]
5565+ | ` Symbolic => [% expr ` symbolic ]
5566+ | ` Fixed => [% expr ` fixed ]
5567+ };
5568+ };
5569+
5570+ let render_list_image_or_string = (~loc, list_image_or_string) => {
5571+ list_image_or_string
5572+ |> List . map(image_or_string =>
5573+ switch (image_or_string) {
5574+ | ` Image (image ) => render_image(~loc, image)
5575+ | ` String (str ) => render_string(~loc, str)
5576+ }
5577+ )
5578+ |> Builder . pexp_array(~loc);
5579+ };
5580+
5581+ let render_symbols =
5582+ (~loc, symbols_type: option (Types . symbols_type ), list_image_or_string) => {
5583+ switch (symbols_type) {
5584+ | Some (symbols_type ) => [% expr
5585+ ` symbols ((
5586+ [% e render_symbols_type(~loc, symbols_type)],
5587+ [% e render_list_image_or_string(~loc, list_image_or_string)],
5588+ ))
5589+ ]
5590+ | None => [% expr
5591+ ` symbols ((
5592+ None ,
5593+ [% e render_list_image_or_string(~loc, list_image_or_string)],
5594+ ))
5595+ ]
5596+ };
5597+ };
5598+
5599+ let render_counter_style = (~loc, counter_style: Types . counter_style ) => {
5600+ switch (counter_style) {
5601+ | ` Counter_style_name (label ) => [% expr
5602+ ` Custom ([% e render_string(~loc, label)])
5603+ ]
5604+ | ` Function_symbols (symbols_type , list_image_or_string ) => [% expr
5605+ [% e render_symbols(~loc, symbols_type, list_image_or_string)]
5606+ ]
5607+ };
5608+ };
5609+
5610+ let render_counter =
5611+ (~loc, label: string , style: option (Types . counter_style )) => {
5612+ switch (style) {
5613+ | Some (counter_style ) => [% expr
5614+ ` counter ((
5615+ [% e render_string(~loc, label)],
5616+ Some ([% e render_counter_style(~loc, counter_style)]),
5617+ ))
5618+ ]
5619+ | None => [% expr ` counter (([% e render_string(~loc, label)], None ))]
5620+ };
5621+ };
5622+
55005623let render_content_list = (~loc, content_list: Types . content_list ) => {
55015624 content_list
55025625 |> List . map(content_item =>
@@ -5505,8 +5628,16 @@ let render_content_list = (~loc, content_list: Types.content_list) => {
55055628 | ` Quote (quote ) => render_quote(~loc, quote)
55065629 | ` String (str ) => render_content_string(~loc, str)
55075630 | ` Url (u ) => render_url(~loc, u)
5508- | ` Counter (_label , _ , _style ) => raise (Unsupported_feature )
5509- | ` Function_attr (_attr ) => raise (Unsupported_feature )
5631+ | ` Counter (counter_name , _ , list_style_type_opt ) =>
5632+ let counter_style_opt =
5633+ switch (list_style_type_opt) {
5634+ | Some (` Counter_style (cs )) => Some (cs)
5635+ | Some (` None | ` String (_ )) => None
5636+ | None => None
5637+ };
5638+ render_counter(~loc, counter_name, counter_style_opt);
5639+ | ` Function_attr ((attr_name , attr_type ): Types . function_attr ) =>
5640+ render_function_attr(~loc, attr_name, attr_type)
55105641 }
55115642 )
55125643 |> Builder . pexp_array(~loc);
0 commit comments