<commit_before>"""This module contains a model element Diagram. Diagrams
can be visualized and edited.

The DiagramCanvas class extends the gaphas.Canvas class.
"""
from __future__ import annotations

import logging
import textwrap
import uuid
from dataclasses import dataclass
from functools import lru_cache
from typing import TYPE_CHECKING, Iterator, Optional, Sequence, Union

import gaphas

from gaphor.core.modeling.collection import collection
from gaphor.core.modeling.coremodel import Element, PackageableElement
from gaphor.core.modeling.element import Id, RepositoryProtocol
from gaphor.core.modeling.event import DiagramItemCreated
from gaphor.core.modeling.presentation import Presentation
from gaphor.core.modeling.stylesheet import StyleSheet
from gaphor.core.styling import Style, StyleNode

if TYPE_CHECKING:
    from cairo import Context as CairoContext

    from gaphor.core.modeling.properties import relation_one
    from gaphor.UML import Package

log = logging.getLogger(__name__)


# Not all styles are requires: "background-color", "font-weight",
# "text-color", and "text-decoration" are optional (can default to None)
FALLBACK_STYLE: Style = {
    "color": (0, 0, 0, 1),
    "font-family": "sans",
    "font-size": 14,
    "highlight-color": (0, 0, 1, 0.4),
    "line-width": 2,
    "padding": (0, 0, 0, 0),
}


DEFAULT_STYLE_SHEET = textwrap.dedent(
    """\
    * {
     background-color: transparent;
     color: black;
     font-family: sans;
     font-size: 14;
     highlight-color: rgba(0, 0, 255, 0.4);
     line-width: 2;
     padding: 0;
    }

    diagram {
     background-color: white;
     line-style: normal;
     /* line-style: sloppy 0.3; */
    }
    """
)


@dataclass(frozen=True)
class UpdateContext:
    """
    Context used when updating items (Presentation's).

    Style contains the base style, no style alterations due to view state
    (focus, hover, etc.).
    """

    style: Style


@dataclass(frozen=True)
class DrawContext:
    """
    Special context for draw()'ing the item. The draw-context contains
    stuff like the cairo context and flags like selected and
    focused.
    """

    cairo: CairoContext
    style: Style
    selected: bool
    focused: bool
    hovered: bool
    dropzone: bool


# From https://www.python.org/dev/peps/pep-0616/
def removesuffix(self: str, suffix: str, /) -> str:
    # suffix='' should not call self[:-0].<commit_msg>Remove strict signature info from removesuffix<commit_after>"""This module contains a model element Diagram. Diagrams
can be visualized and edited.

The DiagramCanvas class extends the gaphas.Canvas class.
"""
from __future__ import annotations

import logging
import textwrap
import uuid
from dataclasses import dataclass
from functools import lru_cache
from typing import TYPE_CHECKING, Iterator, Optional, Sequence, Union

import gaphas

from gaphor.core.modeling.collection import collection
from gaphor.core.modeling.coremodel import Element, PackageableElement
from gaphor.core.modeling.element import Id, RepositoryProtocol
from gaphor.core.modeling.event import DiagramItemCreated
from gaphor.core.modeling.presentation import Presentation
from gaphor.core.modeling.stylesheet import StyleSheet
from gaphor.core.styling import Style, StyleNode

if TYPE_CHECKING:
    from cairo import Context as CairoContext

    from gaphor.core.modeling.properties import relation_one
    from gaphor.UML import Package

log = logging.getLogger(__name__)


# Not all styles are requires: "background-color", "font-weight",
# "text-color", and "text-decoration" are optional (can default to None)
FALLBACK_STYLE: Style = {
    "color": (0, 0, 0, 1),
    "font-family": "sans",
    "font-size": 14,
    "highlight-color": (0, 0, 1, 0.4),
    "line-width": 2,
    "padding": (0, 0, 0, 0),
}


DEFAULT_STYLE_SHEET = textwrap.dedent(
    """\
    * {
     background-color: transparent;
     color: black;
     font-family: sans;
     font-size: 14;
     highlight-color: rgba(0, 0, 255, 0.4);
     line-width: 2;
     padding: 0;
    }

    diagram {
     background-color: white;
     line-style: normal;
     /* line-style: sloppy 0.3; */
    }
    """
)


@dataclass(frozen=True)
class UpdateContext:
    """
    Context used when updating items (Presentation's).

    Style contains the base style, no style alterations due to view state
    (focus, hover, etc.).
    """

    style: Style


@dataclass(frozen=True)
class DrawContext:
    """
    Special context for draw()'ing the item. The draw-context contains
    stuff like the cairo context and flags like selected and
    focused.
    """

    cairo: CairoContext
    style: Style
    selected: bool
    focused: bool
    hovered: bool
    dropzone: bool


# From https://www.python.org/dev/peps/pep-0616/
def removesuffix(self: str, suffix: str) -> str:
    # suffix='' should not call self[:-0].
{'fraction_non_alphanumeric': 0.10234278668310727, 'fraction_numerical': 0.013974517057131115, 'mean_word_length': 3.5232342007434942, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2245672', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1482, 'n_words': 478}