<commit_before>module Canvas exposing (build, buildSvg, iconify)

-- Sketch-n-Sketch Libraries ---------------------------------------------------

import Config exposing (params)
import Utils
import Either exposing (Either(..))
import HtmlUtils exposing (handleEventAndStop)

import Lang exposing (..)
import LangSvg exposing (NodeId, ShapeKind, attr)
import ShapeWidgets exposing
  ( ZoneName, RealZone(..)
  , ShapeFeature, Feature(..), PointFeature(..), DistanceFeature(..), OtherFeature(..)
  , FeatureNum(..)
  )
import SleekLayout
import Sync
import Draw
import InterfaceModel exposing (..)
import FastParser exposing (parseE)
import Eval

-- Elm Libraries ---------------------------------------------------------------

import String
import Dict
import Set
import Color

import VirtualDom
import Json.Decode
import Svg exposing (Svg)
import Svg.Attributes as SAttr
import Svg.Events exposing (onMouseDown, onMouseUp, onMouseOver, onMouseOut)
import Html exposing (Html)
import Html.Attributes as Attr
import Html.Events exposing
  ( onClick, onInput, onMouseEnter, onMouseLeave
  , onWithOptions, defaultOptions
  )


--------------------------------------------------------------------------------

strOldInterfaceColor = "rgba(52,73,94,1.0)"
strOldButtonTopColor = "rgba(231,76,60,1.0)" -- from InterfaceButtons example

--------------------------------------------------------------------------------

pixels n = toString n ++ "px"

svgLine      = flip Svg.line []
svgRect      = flip Svg.rect []
svgCircle    = flip Svg.circle []
svgEllipse   = flip Svg.ellipse []
svgPolygon   = flip Svg.polygon []
svgPath      = flip Svg.path []


--------------------------------------------------------------------------------

msgClickZone zoneKey = Msg ("Click Zone" ++ toString zoneKey) <| \old ->
  case old.mode of
    Live info ->
      -- let _ = Debug.log ("Click Zone" ++ toString zoneKey) () in
      let (_, (mx, my)) = SleekLayout.clickToCanvasPoint old (Tuple.second old.mouseState) in
      let trigger = Sync.prepareLiveTrigger info old.inputExp zoneKey in
      let dragInfo = (trigger, (mx, my), False) in
      { old | mouseMode = MouseDragZone zoneKey (Just dragInfo) }
    _ ->
      old

msgMouseClickCanvas = Msg "MouseClickCanvas" <| \old ->
  case (old.tool, old.mouseMode) of
    (Cursor, MouseDragZone _ _) -> old
    (Cursor, _) ->
      { old | selectedShapes = Set.empty, selectedBlobs = Dict.empty }

    (_ , MouseNothing) ->
      { old | mouseMode = MouseDrawNew NoPointsYet -- No points until drag begins, or (for paths/polys) mouse-up
            , selectedShapes = Set.empty, selectedBlobs = Dict.empty }

    _ -> old


--------------------------------------------------------------------------------


build wCanvas hCanvas model =
  let addZones = case (model.mode, model.preview) of
    (Live _, Nothing) -> model.tool == Cursor
    _                 -> False
  in
  let (widgets, slate) =
    case model.preview of
      Just (_, Ok (val, widgets, slate)) -> (widgets, slate)
      _                                  -> (model.widgets, model.slate)
  in
  let outputShapes = buildSvg (model, addZones) slate in
  let newShape = drawNewShape model in
  let svgWidgets =
    case (model.mode, model.showGhosts) of
      (Live _, True ) -> buildSvgWidgets wCanvas hCanvas widgets model
      _               -> []
  in
  Svg.svg
     [ Attr.id "outputCanvas"
     , onMouseDown msgMouseClickCanvas
     , Attr.style
         [ ("width", pixels wCanvas)
         , ("height", pixels hCanvas)<commit_msg>Disable manipulation of output in user study<commit_after>module Canvas exposing (build, buildSvg, iconify)

-- Sketch-n-Sketch Libraries ---------------------------------------------------

import Config exposing (params)
import Utils
import Either exposing (Either(..))
import HtmlUtils exposing (handleEventAndStop)
import UserStudy

import Lang exposing (..)
import LangSvg exposing (NodeId, ShapeKind, attr)
import ShapeWidgets exposing
  ( ZoneName, RealZone(..)
  , ShapeFeature, Feature(..), PointFeature(..), DistanceFeature(..), OtherFeature(..)
  , FeatureNum(..)
  )
import SleekLayout
import Sync
import Draw
import InterfaceModel exposing (..)
import FastParser exposing (parseE)
import Eval

-- Elm Libraries ---------------------------------------------------------------

import String
import Dict
import Set
import Color

import VirtualDom
import Json.Decode
import Svg exposing (Svg)
import Svg.Attributes as SAttr
import Svg.Events exposing (onMouseDown, onMouseUp, onMouseOver, onMouseOut)
import Html exposing (Html)
import Html.Attributes as Attr
import Html.Events exposing
  ( onClick, onInput, onMouseEnter, onMouseLeave
  , onWithOptions, defaultOptions
  )


--------------------------------------------------------------------------------

strOldInterfaceColor = "rgba(52,73,94,1.0)"
strOldButtonTopColor = "rgba(231,76,60,1.0)" -- from InterfaceButtons example

--------------------------------------------------------------------------------

pixels n = toString n ++ "px"

svgLine      = flip Svg.line []
svgRect      = flip Svg.rect []
svgCircle    = flip Svg.circle []
svgEllipse   = flip Svg.ellipse []
svgPolygon   = flip Svg.polygon []
svgPath      = flip Svg.path []


--------------------------------------------------------------------------------

msgClickZone zoneKey = Msg ("Click Zone" ++ toString zoneKey) <| \old ->
  case old.mode of
    Live info ->
      -- let _ = Debug.log ("Click Zone" ++ toString zoneKey) () in
      let (_, (mx, my)) = SleekLayout.clickToCanvasPoint old (Tuple.second old.mouseState) in
      let trigger = Sync.prepareLiveTrigger info old.inputExp zoneKey in
      let dragInfo = (trigger, (mx, my), False) in
      { old | mouseMode = MouseDragZone zoneKey (Just dragInfo) }
    _ ->
      old

msgMouseClickCanvas = Msg "MouseClickCanvas" <| \old ->
  case (old.tool, old.mouseMode) of
    (Cursor, MouseDragZone _ _) -> old
    (Cursor, _) ->
      { old | selectedShapes = Set.empty, selectedBlobs = Dict.empty }

    (_ , MouseNothing) ->
      { old | mouseMode = MouseDrawNew NoPointsYet -- No points until drag begins, or (for paths/polys) mouse-up
            , selectedShapes = Set.empty, selectedBlobs = Dict.empty }

    _ -> old


--------------------------------------------------------------------------------


build wCanvas hCanvas model =
  let addZones = case (UserStudy.enabled, model.mode, model.preview) of
    (True, _, _)         -> False
    (_, Live _, Nothing) -> model.tool == Cursor
    _                 -> False
  in
  let (widgets, slate) =
    case model.preview of
      Just (_, Ok (val, widgets, slate)) -> (widgets, slate)
      _                                  -> (model.widgets, model.slate)
  in
  let outputShapes = buildSvg (model, addZones) slate in
  let newShape = drawNewShape model in
  let svgWidgets =
    case (model.mode, model.showGhosts) of
      (Live _, True ) -> buildSvgWidgets wCanvas hCanvas widgets model
      _               -> []
  in
  Svg.svg
     [ Attr.id "outputCanvas"
     , onMouseDown msgMouseClickCanvas
     , Attr.style
         [ ("width", pixels wCanvas)
         , ("height", pixels hCanvas)
{'fraction_non_alphanumeric': 0.2150013915947676, 'fraction_numerical': 0.004731422209852491, 'mean_word_length': 1.9286878565607173, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7436490', 'n_tokens_mistral': 2075, 'n_tokens_neox': 1990, 'n_words': 586}