<commit_before>// $begin{copyright}
//
// This file is part of WebSharper
//
// Copyright (c) 2008-2014 IntelliFactory
//
// Licensed under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License.  You may
// obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.  See the License for the specific language governing
// permissions and limitations under the License.
//
// $end{copyright}

namespace WebSharper.UI.Next

type Attr =
    | AppendAttr of list<Attr>
    | SingleAttr of string * string * option<WebSharper.Html.Client.IRequiresResources>

    static member Create name value =
        SingleAttr(name, value, None)

    static member Append a b =
        AppendAttr [a; b]

    static member Empty =
        AppendAttr []

    static member Concat (xs: seq<Attr>) =
        AppendAttr (List.ofSeq xs)

namespace WebSharper.UI.Next.Server

open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open WebSharper.UI.Next
open WebSharper.Html.Server
module M = WebSharper.Core.Metadata
module P = WebSharper.Core.JavaScript.Packager
module R = WebSharper.Core.Reflection

module Attr =

    let getLocation (q: Expr) =
        let (|Val|_|) e : 't option =
            match e with
            | Quotations.Patterns.Value(:? 't as v,_) -> Some v
            | _ -> None
        let l =
            q.CustomAttributes |> Seq.tryPick (function
                | NewTuple [ Val "DebugRange";
                             NewTuple [ Val (file: string)
                                        Val (startLine: int)
                                        Val (startCol: int)
                                        Val (endLine: int)
                                        Val (endCol: int) ] ] ->
                    Some (sprintf "%s: %i.%i-%i.%i" file startLine startCol endLine endCol)
                | _ -> None)
        defaultArg l "(no location)"

    let gen = System.Random()

    type Requires(reqs) =

        [<System.NonSerialized>]
        let reqs = reqs

        interface WebSharper.Html.Client.IRequiresResources with
            member this.Requires meta = reqs :> seq<_>

    let Handler (event: string) (q: Expr<#WebSharper.JavaScript.Dom.Event -> unit>) =
        let declType, name, reqs =
            match q with
            | Lambda (x1, Call(None, m, [Var x2])) when x1 = x2 ->
                let rm = R.Method.Parse m
                rm.DeclaringType, rm.Name, [M.MethodNode rm; M.TypeNode rm.DeclaringType]
            | _ -> failwithf "Invalid handler function: %A" q
        let func =
            match WebSharper.Web.Shared.Metadata.GetAddress declType with
            | None ->
                failwithf "Error in Handler at %s: Couldn't find address for method"
                    (getLocation q)
            | Some a ->
                let rec mk acc (a: P.Address) =
                    let acc = a.LocalName :: acc
                    match a.Parent with
                    | None -> acc
                    | Some p -> mk acc p
                String.concat "." (mk [name] a)
        SingleAttr("on" + event, func + "(event)", Some (Requires(reqs) :> _))

    let rec AsAttributes attr : list<Attribute> =
        match attr with
        | AppendAttr a ->
            List.collect AsAttributes a
        | SingleAttr(name, value, req) ->
            [{Name = name; Value = value; Annotation = req}]

namespace WebSharper.UI.Next.Client

open WebSharper
open WebSharper.JavaScript
open WebSharper.UI.Next
module DU = DomUtility

type IAttrNode =
    abstract Changed : View<unit>
    abstract GetChangeAnim : Element -> Anim
    abstract GetEnterAnim : Element -> Anim
    abstract GetExitAnim : Element -> Anim
    abstract Sync : Element -> unit

[<JavaScript>]
[<Sealed>]
type AnimatedAttrNode<'T>(tr: Trans<'T>, view: View<'T>, push: Element -> 'T -> unit) =
    let mutable logical : option<'T> = None // current logical value
    let mutable visible : option<'T> = None // current value pushed to the parent element
    let mutable dirty = true // logical <> visible<commit_msg>Server.Attr.Handler: use metadata from Requires<commit_after>// $begin{copyright}
//
// This file is part of WebSharper
//
// Copyright (c) 2008-2014 IntelliFactory
//
// Licensed under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License.  You may
// obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.  See the License for the specific language governing
// permissions and limitations under the License.
//
// $end{copyright}

namespace WebSharper.UI.Next

type Attr =
    | AppendAttr of list<Attr>
    | SingleAttr of WebSharper.Html.Server.Html.Attribute

    static member Create name value =
        SingleAttr { Name = name; Value = value; Annotation = None }

    static member Append a b =
        AppendAttr [a; b]

    static member Empty =
        AppendAttr []

    static member Concat (xs: seq<Attr>) =
        AppendAttr (List.ofSeq xs)

namespace WebSharper.UI.Next.Server

open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open WebSharper.UI.Next
open WebSharper.Html.Server
module M = WebSharper.Core.Metadata
module P = WebSharper.Core.JavaScript.Packager
module R = WebSharper.Core.Reflection

module Attr =

    let getLocation (q: Expr) =
        let (|Val|_|) e : 't option =
            match e with
            | Quotations.Patterns.Value(:? 't as v,_) -> Some v
            | _ -> None
        let l =
            q.CustomAttributes |> Seq.tryPick (function
                | NewTuple [ Val "DebugRange";
                             NewTuple [ Val (file: string)
                                        Val (startLine: int)
                                        Val (startCol: int)
                                        Val (endLine: int)
                                        Val (endCol: int) ] ] ->
                    Some (sprintf "%s: %i.%i-%i.%i" file startLine startCol endLine endCol)
                | _ -> None)
        defaultArg l "(no location)"

    let gen = System.Random()

    type Requires(reqs, onGetRequires: M.Info -> unit) =

        [<System.NonSerialized>]
        let reqs = reqs

        interface WebSharper.Html.Client.IRequiresResources with
            member this.Requires meta =
                onGetRequires meta
                reqs :> seq<_>

    let Handler (event: string) (q: Expr<#WebSharper.JavaScript.Dom.Event -> unit>) =
        let declType, name, reqs =
            match q with
            | Lambda (x1, Call(None, m, [Var x2])) when x1 = x2 ->
                let rm = R.Method.Parse m
                rm.DeclaringType, rm.Name, [M.MethodNode rm; M.TypeNode rm.DeclaringType]
            | _ -> failwithf "Invalid handler function: %A" q
        let rec attr : WebSharper.Html.Server.Html.Attribute =
            { Name = "on" + event
              Value = ""
              Annotation = Some (Requires(reqs, func) :> _) }
        and func (meta: M.Info) =
            match meta.GetAddress declType with
            | None ->
                failwithf "Error in Handler at %s: Couldn't find address for method"
                    (getLocation q)
            | Some a ->
                let rec mk acc (a: P.Address) =
                    let acc = a.LocalName :: acc
                    match a.Parent with
                    | None -> acc
                    | Some p -> mk acc p
                attr.Value <- String.concat "." (mk [name] a) + "(event)"
        SingleAttr attr 

    let rec AsAttributes attr : list<Attribute> =
        match attr with
        | AppendAttr a -> List.collect AsAttributes a
        | SingleAttr a -> [a]

namespace WebSharper.UI.Next.Client

open WebSharper
open WebSharper.JavaScript
open WebSharper.UI.Next
module DU = DomUtility

type IAttrNode =
    abstract Changed : View<unit>
    abstract GetChangeAnim : Element -> Anim
    abstract GetEnterAnim : Element -> Anim
    abstract GetExitAnim : Element -> Anim
    abstract Sync : Element -> unit

[<JavaScript>]
[<Sealed>]
type AnimatedAttrNode<'T>(tr: Trans<'T>, view: View<'T>, push: Element -> 'T -> unit) =
    let mutable logical : option<'T> = None // current logical value
    let mutable visible : option<'T> = None // current value pushed to the parent element
    let mutable dirty = true // logical <> visible
{'fraction_non_alphanumeric': 0.09983155530600786, 'fraction_numerical': 0.003593486805165637, 'mean_word_length': 1.937335092348285, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2852875', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2463, 'n_words': 832}