{
  "controller": "MistExpressionDemoController",
  "styles": {
    "title": {
      "font-style": "bold",
      "font-size": 15,
      "padding-top": 15,
      "padding-left": 10,
      "padding-bottom": 1,
      "color": "#666",
      "background-color": "#ddd"
    },
    "subtitle": {
      "lines": 0,
      "font-size": 12,
      "font-style": "light",
      "padding-bottom": 4,
      "padding-left": 10,
      "color": "#999",
      "background-color": "#ddd"
    },
    "header": {
      "color": "white",
      "background-color": "#6FE24810",
      "width": "50%",
      "font-size": 12,
      "font-style": "light",
      "lines": 0,
      "alignment": "center"
    },
    "code": {
      "font-size": 12,
      "font-name": "Courier New",
      "lines": 0,
      "line-spacing": 1,
      "padding": 6
    }
  },
  "layout": {
    "vars": {
      "themeColor": "#E24810",
      "groups": [
        {
          "desc": "注意，<tt><b>.</b></tt> 运算符不带参数时会优先尝试 dictionary 取值，可以在末尾加 <tt><b>()</b></tt> 显式指定调用函数，如：<tt><b>array.count()</b></tt>",
          "exps": [
            "{'a': 10, 'count': 20}.count",
            "{'a': 10, 'count': 20}.count()"
          ]
        },
        {
          "title": "Category 扩展",
          "desc": "可以用 Category 为一些基本类型增加扩展方法，增加的扩展方法为避免与其它 framework 冲突，最好加一个 <tt><b>vzt_</b></tt> 前缀，如：<font size='11' color='#666'><tt><br>@implementation NSString (VZTExtension)<br>- (NSArray *)vzt_split:(NSString *)separator {<br>&nbsp;&nbsp;&nbsp;&nbsp;return [self componentsSeparatedByString:separator];<br>}<br>@end</tt></font>",
          "exps": [
            "'a bb ccc'.split(' ')"
          ]
        }
      ]
    },
    "style": {
      "direction": "vertical",
      "height": "${_height_ - 44 - screen.statusBarHeight - screen.safeArea.bottom}",
      "background-color": "#ddd"
    },
    "children": [
      {
        "type": "scroll",
        "tag": 1,
        "style": {
          "direction": "vertical",
          "scroll-direction": "vertical",
          "flex-grow": 1
        },
        "children": [
          {
            "style": {
              "direction": "vertical"
            },
            "children": [
              {
                "type": "text",
                "class": "title",
                "style": {
                  "text": "方法名转换"
                }
              },
              {
                "type": "text",
                "class": "subtitle",
                "style": {
                  "html-text": "方法调用规则类似 JSPatch，使用下划线 <tt><b>_</b></tt> 替换掉 selector 中的 <tt><b>:</b></tt>，末尾的 <tt><b>:</b></tt> 可省略"
                }
              },
              {
                "style": {
                  "height": "1px",
                  "background-color": "#888"
                }
              },
              {
                "vars": {
                  "list": [
                    [
                      "str.length",
                      "str.length"
                    ],
                    [
                      "[array addObject:@1]",
                      "array.addObject(1)"
                    ],
                    [
                      "[str replace:@\"a\" with:@\"b\"]",
                      "str.replace_with('a', 'b')"
                    ],
                    [
                      "[obj a_b:123]",
                      "obj.a__b(123)"
                    ],
                    [
                      "[SomeClass classMethod]",
                      "SomeClass.classMethod()"
                    ],
                    [
                      "[VZTGlobalFunctions max:1 :2]",
                      "VZTGlobalFunctions.max(1, 2)"
                    ]
                  ]
                },
                "style": {
                  "direction": "vertical"
                },
                "children": [
                  {
                    "style": {
                      "spacing": "1px",
                      "height": 20
                    },
                    "children": [
                      {
                        "type": "text",
                        "class": "header",
                        "style": {
                          "text": "Objective-C"
                        }
                      },
                      {
                        "type": "text",
                        "class": "header",
                        "style": {
                          "text": "模版表达式"
                        }
                      }
                    ]
                  },
                  {
                    "style": {
                      "height": "1px",
                      "background-color": "#ccc"
                    }
                  },
                  {
                    "repeat": "${list}",
                    "style": {
                      "spacing": "1px"
                    },
                    "children": [
                      {
                        "type": "text",
                        "class": "code",
                        "style": {
                          "text": "${_item_[0]}",
                          "width": "50%",
                          "alignment": "center",
                          "background-color": "${_index_ % 2 == 0 ? '#1FE24810' : '#2FE24810'}"
                        }
                      },
                      {
                        "type": "text",
                        "class": "code",
                        "style": {
                          "text": "${_item_[1]}",
                          "width": "50%",
                          "alignment": "center",
                          "background-color": "${_index_ % 2 == 0 ? '#1FE24810' : '#2FE24810'}"
                        }
                      }
                    ]
                  }
                ]
              },
              {
                "style": {
                  "height": "1px",
                  "background-color": "#888"
                }
              }
            ]
          },
          {
            "repeat": "${groups}",
            "style": {
              "direction": "vertical"
            },
            "children": [
              {
                "type": "text",
                "class": "title",
                "style": {
                  "text": "${_item_.title}"
                }
              },
              {
                "type": "text",
                "class": "subtitle",
                "style": {
                  "html-text": "${_item_.desc}"
                }
              },
              {
                "style": {
                  "height": "1px",
                  "background-color": "#888"
                }
              },
              {
                "style": {
                  "direction": "vertical"
                },
                "children": [
                  {
                    "style": {
                      "spacing": "1px",
                      "height": 20
                    },
                    "children": [
                      {
                        "type": "text",
                        "class": "header",
                        "style": {
                          "text": "表达式",
                        }
                      },
                      {
                        "type": "text",
                        "class": "header",
                        "style": {
                          "text": "结果"
                        }
                      }
                    ]
                  },
                  {
                    "style": {
                      "height": "1px",
                      "background-color": "#ccc"
                    }
                  },
                  {
                    "repeat": "${_item_.exps}",
                    "vars": {
                      "action": {
                        "updateState:": {
                          "exp": "${_item_}"
                        }
                      }
                    },
                    "style": {
                      "spacing": "1px"
                    },
                    "on-tap": "${state.try ? action : nil}",
                    "children": [
                      {
                        "type": "text",
                        "class": "code",
                        "style": {
                          "text": "${_item_}",
                          "width": "50%",
                          "background-color": "${_index_ % 2 == 0 ? '#1FE24810' : '#2FE24810'}"
                        }
                      },
                      {
                        "type": "text",
                        "class": "code",
                        "style": {
                          "text": "${MistExpressionDemoController.toString(eval(_item_))}",
                          "width": "50%",
                          "background-color": "${_index_ % 2 == 0 ? '#1FE24810' : '#2FE24810'}",
                          "alignment": "center"
                        }
                      }
                    ]
                  }
                ]
              },
              {
                "style": {
                  "height": "1px",
                  "background-color": "#888"
                }
              }
            ]
          }
        ]
      },
      {
        "tag": 2,
        "on-tap": {
          "updateState:": {
            "try": "${!state.try}"
          }
        },
        "style": {
          "auto-animation": true,
          "margin-top": "auto",
          "background-color": "#E24810",
          "direction": "vertical",
          "padding-bottom": "${screen.safeArea.bottom}",
          "margin-bottom": "${-screen.safeArea.bottom}"
        },
        "children": [
          {
            "type": "text",
            "style": {
              "flex-grow": "${state.try ? 0 : 1}",
              "text": "试一试",
              "color": "white",
              "font-size": "${state.try ? 12 : 15}",
              "font-style": "bold",
              "margin-right": "auto",
              "margin-left": "${state.try ? 7 : 'auto'}",
              "margin-top": "${state.try ? 3 : 8}",
              "margin-bottom": "${state.try ? 3 : 8}"
            }
          },
          {
            "gone": "${!state.try}",
            "on-update-appear": {
              "type": "animation",
              "params": {
                "delay": 0.2,
                "duration": 0.2,
                "fill-mode": "backwards",
                "key-path": "opacity",
                "from": 0
              }
            },
            "on-update-disappear": {
              "type": "animation",
              "params": {
                "duration": 0.2,
                "animations": [
                  {
                    "key-path": "hidden",
                    "from": false,
                    "duration": 0.4
                  },
                  {
                    "key-path": "opacity",
                    "to": 0
                  }
                ]
              }
            },
            "tag": 1,
            "style": {
              "direction": "vertical"
            },
            "children": [
              {
                "type": "textview",
                "on-display": {
                  "onDisplay:sender:": ""
                },
                "on-change": {
                  "onTextChange:body:": ""
                },
                "style": {
                  "height": 60,
                  "background-color": "white",
                  "corner-radius-top-left": 3,
                  "corner-radius-top-right": 3,
                  "text": "${state.exp}",
                  "placeholder": "在此输入表达式",
                  "keyboard-type": "ascii-capable",
                  "font-size": 12,
                  "font-name": "Courier New",
                  "lines": 0,
                  "line-spacing": 1,
                  "padding": 4,
                  "padding-left": -1,
                  "padding-right": -1,
                  "margin-left": 5,
                  "margin-right": 5
                }
              },
              {
                "type": "text",
                "style": {
                  "background-color": "white",
                  "corner-radius-bottom-left": 3,
                  "corner-radius-bottom-right": 3,
                  "html-text": "<font color='#aaa' size='12'>结果：</font>${MistExpressionDemoController.toString(eval(state.exp))}",
                  "font-name": "Courier New",
                  "font-size": 12,
                  "line-spacing": 1,
                  "lines": 0,
                  "padding": 4,
                  "margin": 5,
                  "margin-top": "1px"
                }
              }
            ]
          }
        ]
      }
    ]
  }
}