Skip to content

yzsp-studio/mediakit-shared-suite / ppt

飞书幻灯片:创建和编辑幻灯片。创建演示文稿、读取幻灯片内容、管理幻灯片页面(创建、删除、读取、局部替换)。当用户需要创建或编辑幻灯片、读取或修改单个页面时使用。

FileKindSize
SKILL.mdskill md40.1 KB
references/cli/lark-slides-add-slide.mdmarkdown7.3 KB
references/cli/lark-slides-create.mdmarkdown10.5 KB
references/cli/lark-slides-delete-slide.mdmarkdown2.7 KB
references/cli/lark-slides-history.mdmarkdown6.9 KB
references/cli/lark-slides-media-upload.mdmarkdown5.5 KB
references/cli/lark-slides-replace-slide.mdmarkdown14.8 KB
references/cli/lark-slides-screenshot.mdmarkdown5.4 KB
references/cli/lark-slides-update-slide.mdmarkdown11.6 KB
references/cli/lark-slides-xml-presentation-slide-get.mdmarkdown3.6 KB
references/cli/lark-slides-xml-presentation-slide-replace.mdmarkdown7.3 KB
references/cli/lark-slides-xml-presentations-get.mdmarkdown9.4 KB
references/refine/academic-research.mdmarkdown7.3 KB
references/refine/brand-storytelling.mdmarkdown8.3 KB
references/refine/business-pitch.mdmarkdown8.0 KB
references/refine/business-review.mdmarkdown8.3 KB
references/refine/fallback.mdmarkdown7.8 KB
references/refine/learning-and-training.mdmarkdown8.5 KB
references/refine/strategy-and-analysis.mdmarkdown8.1 KB
references/refine/technical-presentation.mdmarkdown8.1 KB
references/style/academic-research.mdmarkdown18.5 KB
references/style/brand-storytelling.mdmarkdown34.1 KB
references/style/business-pitch.mdmarkdown12.2 KB
references/style/business-review.mdmarkdown19.6 KB
references/style/fallback.mdmarkdown8.7 KB
references/style/learning-and-training.mdmarkdown20.8 KB
references/style/slide-taxonomy.mdmarkdown13.6 KB
references/style/strategy-and-analysis.mdmarkdown8.4 KB
references/style/technical-presentation.mdmarkdown15.6 KB
references/workflow/error-handling.mdmarkdown9.6 KB
references/workflow/local-compat.mdmarkdown5.3 KB
references/workflow/slides-editing.mdmarkdown34.6 KB
references/workflow/template-editing-main.mdmarkdown36.6 KB
references/workflow/template-editing-organizer.mdmarkdown24.4 KB
references/workflow/validation-visual.mdmarkdown7.1 KB
references/workflow/validation-xml.mdmarkdown31.9 KB
references/workflow/windows-compat.mdmarkdown6.3 KB
references/xml/fonts.mdmarkdown7.6 KB
references/xml/iconpark-index.jsonconfig729.4 KB
references/xml/iconpark.mdmarkdown2.1 KB
references/xml/slides_chart_demo.xmlconfig69.2 KB
references/xml/slides_xml_schema_definition.xmlconfig228.6 KB
references/xml/xml-schema-quick-ref.mdmarkdown34.7 KB
scripts/atomize_svg_to_slide.pyscript80.2 KB
scripts/atomize_svg_to_slide_test.pyscript5.5 KB
scripts/color_contrast_check.pyscript36.4 KB
scripts/color_contrast_check_test.pyscript28.9 KB
scripts/embed_svg_validator.pyscript56.7 KB
scripts/embed_svg_validator_test.pyscript18.2 KB
scripts/gen_svg_charts.pyscript48.8 KB
scripts/gen_svg_relations.pyscript42.6 KB
scripts/iconpark_tool.pyscript12.1 KB
scripts/iconpark_tool_test.pyscript7.7 KB
scripts/lint_inspect.pyscript23.3 KB
scripts/lint_inspect_test.pyscript13.2 KB
scripts/parse_template.pyscript114.0 KB
scripts/purge_deck.pyscript11.4 KB
scripts/safe_update_slide.pyscript21.0 KB
scripts/svg_lib/_baseline.pyscript50.9 KB
scripts/svg_lib/_boxplot_skin.pyscript21.5 KB
scripts/svg_lib/_common.pyscript46.6 KB
scripts/svg_lib/charts/__init__.pyscript853 B
scripts/svg_lib/charts/_shared.pyscript8.6 KB
scripts/svg_lib/charts/boxplot.pyscript26.9 KB
scripts/svg_lib/charts/calheat.pyscript45.7 KB
scripts/svg_lib/charts/candle.pyscript39.1 KB
scripts/svg_lib/charts/event_timeline.pyscript66.6 KB
scripts/svg_lib/charts/funnel.pyscript54.6 KB
scripts/svg_lib/charts/gantt.pyscript53.6 KB
scripts/svg_lib/charts/marimekko.pyscript26.9 KB
scripts/svg_lib/charts/matrix_heat.pyscript52.3 KB
scripts/svg_lib/charts/nested_donut.pyscript61.2 KB
scripts/svg_lib/charts/percent_grid.pyscript38.6 KB
scripts/svg_lib/charts/pyramid.pyscript44.8 KB
scripts/svg_lib/charts/quadrant.pyscript76.8 KB
scripts/svg_lib/charts/ridge.pyscript28.7 KB
scripts/svg_lib/charts/sankey.pyscript48.9 KB
scripts/svg_lib/charts/violin.pyscript37.2 KB
scripts/svg_lib/charts/waterfall.pyscript52.3 KB
scripts/svg_lib/svg_palettes.pyscript52.7 KB
scripts/svg_relation_lib/__init__.pyscript2.0 KB
scripts/svg_relation_lib/_viewbox.pyscript10.5 KB
scripts/svg_relation_lib/attributes/__init__.pyscript1.4 KB
scripts/svg_relation_lib/attributes/_resolver.pyscript1.3 KB
scripts/svg_relation_lib/attributes/_test_attrs.pyscript11.8 KB
scripts/svg_relation_lib/attributes/_test_pipeline.pyscript12.5 KB
scripts/svg_relation_lib/attributes/apply.pyscript5.3 KB
scripts/svg_relation_lib/attributes/category.pyscript1.5 KB
scripts/svg_relation_lib/attributes/confidence.pyscript1.5 KB
scripts/svg_relation_lib/attributes/directional.pyscript1.4 KB
scripts/svg_relation_lib/attributes/highlight.pyscript1.6 KB
scripts/svg_relation_lib/attributes/signed.pyscript1.7 KB
scripts/svg_relation_lib/attributes/size.pyscript1.3 KB
scripts/svg_relation_lib/attributes/status.pyscript2.1 KB
scripts/svg_relation_lib/attributes/temporal.pyscript2.5 KB
scripts/svg_relation_lib/attributes/typed.pyscript1.6 KB
scripts/svg_relation_lib/attributes/weighted.pyscript1.4 KB
scripts/svg_relation_lib/chrome.pyscript9.1 KB
scripts/svg_relation_lib/engine.pyscript11.5 KB
scripts/svg_relation_lib/layouts/__init__.pyscript383 B
scripts/svg_relation_lib/layouts/bloom_v2.pyscript37.9 KB
scripts/svg_relation_lib/layouts/c4_container_v2.pyscript35.1 KB
scripts/svg_relation_lib/layouts/column_stack.pyscript5.3 KB
scripts/svg_relation_lib/layouts/fishbone_v2.pyscript38.1 KB
scripts/svg_relation_lib/layouts/hub_fanout.pyscript15.5 KB
scripts/svg_relation_lib/layouts/osi_stack_v2.pyscript32.8 KB
scripts/svg_relation_lib/layouts/vertical_chain.pyscript4.5 KB
scripts/svg_relation_lib/palettes.pyscript8.9 KB
scripts/svg_relation_lib/palettes_ext.pyscript17.2 KB
scripts/svg_relation_lib/presets/__init__.pyscript297 B
scripts/svg_relation_lib/presets/_chrome.pyscript1.6 KB
scripts/svg_relation_lib/presets/hero_embed_01_AL_fishbone_v2.pyscript21.7 KB
scripts/svg_relation_lib/presets/hero_embed_02_PY_pmf_v2.pyscript16.5 KB
scripts/svg_relation_lib/presets/hero_embed_03_BL_bloom_v2.pyscript44.0 KB
scripts/svg_relation_lib/presets/hero_embed_04_J1_osi_v2.pyscript46.2 KB
scripts/svg_relation_lib/presets/hero_embed_05_MP_mindmap_v2.pyscript28.6 KB
scripts/svg_relation_lib/presets/hero_embed_07_TX_taxonomy_v2.pyscript64.7 KB
scripts/svg_relation_lib/presets/hero_embed_08_KP_kpi_v2.pyscript79.5 KB
scripts/svg_relation_lib/presets/hero_embed_09_E2_5why_v2.pyscript39.4 KB
scripts/svg_relation_lib/presets/hero_embed_10_CS_c4_v2.pyscript173.5 KB
scripts/svg_relation_lib/presets/hero_embed_32_CU2_curriculum_v2.pyscript66.1 KB
scripts/svg_relation_lib/presets/hero_embed_49_FT_faulttree_v2.pyscript69.4 KB
scripts/svg_relation_lib/render.pyscript28.0 KB
scripts/svg_relation_lib/render/render_bl_bloom_tests.pyscript8.2 KB
scripts/svg_relation_lib/render/render_cu2_curriculum_variants.pyscript19.6 KB
scripts/svg_relation_lib/render/render_e2_5why_variants.pyscript8.9 KB
scripts/svg_relation_lib/render/render_ft_faulttree_variants.pyscript12.8 KB
scripts/svg_relation_lib/render/render_j1_osi_tests.pyscript12.0 KB
scripts/svg_relation_lib/render/render_py_pmf_variants.pyscript13.0 KB
scripts/svg_relation_lib/render/render_tx_taxonomy_variants.pyscript17.6 KB
scripts/svg_relation_lib/schemas/__init__.pyscript280 B
scripts/svg_relation_lib/schemas/graph.pyscript1.5 KB
scripts/svg_relation_lib/schemas/tree.pyscript11.2 KB
scripts/svg_relation_lib/skeletons.pyscript15.3 KB
scripts/svg_relation_lib/skins/__init__.pyscript1.3 KB
scripts/svg_relation_lib/skins/_base.pyscript10.0 KB
scripts/svg_relation_lib/skins/annual_report_ivory.pyscript9.1 KB
scripts/svg_relation_lib/skins/art_deco.pyscript27.1 KB
scripts/svg_relation_lib/skins/arxiv_clean.pyscript9.1 KB
scripts/svg_relation_lib/skins/arxiv_pastel.pyscript9.0 KB
scripts/svg_relation_lib/skins/bain_scarlet.pyscript9.0 KB
scripts/svg_relation_lib/skins/bauhaus_primary.pyscript9.2 KB
scripts/svg_relation_lib/skins/bcg_forest.pyscript9.0 KB
scripts/svg_relation_lib/skins/bloomberg_amber.pyscript9.2 KB
scripts/svg_relation_lib/skins/blueprint_grid.pyscript9.6 KB
scripts/svg_relation_lib/skins/boardroom_navy.pyscript29.9 KB
scripts/svg_relation_lib/skins/chalkboard_slate.pyscript9.0 KB
scripts/svg_relation_lib/skins/coursera_indigo.pyscript9.0 KB
scripts/svg_relation_lib/skins/couture_noir.pyscript33.0 KB
scripts/svg_relation_lib/skins/deloitte_lime.pyscript8.9 KB
scripts/svg_relation_lib/skins/duolingo_cream.pyscript20.4 KB
scripts/svg_relation_lib/skins/editorial.pyscript6.4 KB
scripts/svg_relation_lib/skins/editorial_atelier.pyscript60.7 KB
scripts/svg_relation_lib/skins/editorial_atelier_lark.pyscript19.6 KB
scripts/svg_relation_lib/skins/editorial_atelier_tokens.mdmarkdown13.6 KB
scripts/svg_relation_lib/skins/engineering_kraft.pyscript9.0 KB
scripts/svg_relation_lib/skins/goldman_slate.pyscript9.1 KB
scripts/svg_relation_lib/skins/hermes_orange.pyscript9.0 KB
scripts/svg_relation_lib/skins/ib_editorial.pyscript28.9 KB
scripts/svg_relation_lib/skins/journal_ivory.pyscript29.7 KB
scripts/svg_relation_lib/skins/khan_teal.pyscript9.0 KB
scripts/svg_relation_lib/skins/luxury_manual.pyscript20.4 KB
scripts/svg_relation_lib/skins/manuscript_sepia.pyscript9.1 KB
scripts/svg_relation_lib/skins/mbb_consulting.pyscript32.8 KB
scripts/svg_relation_lib/skins/medical_chart.pyscript22.6 KB
scripts/svg_relation_lib/skins/monocle_ecru.pyscript9.1 KB
scripts/svg_relation_lib/skins/napkin.pyscript6.3 KB
scripts/svg_relation_lib/skins/notebook_grid.pyscript9.2 KB
scripts/svg_relation_lib/skins/oxford_indigo.pyscript9.1 KB
scripts/svg_relation_lib/skins/pitch_bauhaus.pyscript9.1 KB
scripts/svg_relation_lib/skins/pitch_ivory.pyscript18.7 KB
scripts/svg_relation_lib/skins/pitch_midnight.pyscript9.1 KB
scripts/svg_relation_lib/skins/pitch_neon.pyscript32.2 KB
scripts/svg_relation_lib/skins/pitch_sunset.pyscript9.1 KB
scripts/svg_relation_lib/skins/registry.pyscript8.5 KB
scripts/svg_relation_lib/skins/riso_duotone.pyscript9.0 KB
scripts/svg_relation_lib/skins/roland_terracotta.pyscript9.0 KB
scripts/svg_relation_lib/skins/saas_product.pyscript38.6 KB
scripts/svg_relation_lib/skins/strategic_briefing.pyscript31.3 KB
scripts/svg_relation_lib/skins/swiss_grid.pyscript8.9 KB
scripts/svg_relation_lib/skins/symposium_ash.pyscript9.2 KB
scripts/svg_relation_lib/skins/technical_whitepaper.pyscript23.7 KB
scripts/svg_relation_lib/skins/terminal_matrix.pyscript9.2 KB
scripts/svg_relation_lib/skins/wabi_sabi.pyscript9.3 KB
scripts/svg_relation_lib/skins/wsj_broadsheet.pyscript9.1 KB
scripts/sxsd_validator.pyscript38.4 KB
scripts/template_lint_all.pyscript48.1 KB
scripts/xml_inspect.pyscript19.8 KB
scripts/xml_inspect_test.pyscript17.7 KB
scripts/xml_lint.pyscript226.8 KB
scripts/xml_lint_test.pyscript346.9 KB

scripts/svg_relation_lib/skins/editorial_atelier_lark.py

View on GitHub
"""editorial_atelier · Lark Slides native backend

平行于 editorial_atelier.py 的 SVG primitive · 输出**飞书 slide 原生 XML** 而不是 SVG.
每个 primitive 返回 slide XML 片段字符串 · preset 拼一整页 <slide>.

飞书 slide canvas 是 960×540. hero_embed preset canvas 是 900×336.
坐标偏移: DX=30 · DY=102 · 让 900×336 body 居中于 slide.

设计原则:
- 每 chip / label / hub / line 是**独立** slide-native element (shape/line/text)
- 用户在 slide 里 · 每个都能单击选中 · 双击改字 · 拖动 · 改色
- filter/gradient/halo 装饰效果**无**(slide-native shape 不支持 SVG filter)· 用简单 fill+border 表达
- 与 editorial_atelier.py 视觉 90% 一致 · 剩下 10% 是 halo/shadow/ribbon 精细装饰的损失
"""
from __future__ import annotations

from typing import Optional


# ═════════════════════════════════════════════════════════════════
# Design tokens · 从 editorial_atelier.py 复用
# ═════════════════════════════════════════════════════════════════

HUE_HEX = {
    "rust":     "#A35832",
    "orange":   "#C87F3D",
    "magenta":  "#A63C6E",
    "blue":     "#3F6892",
    "green":    "#558045",
    "olive":    "#7A6A3A",
    "cinnamon": "#8B5A3C",
    "gold_p":   "#D9A448",
}

INK = "#1C1914"
BONE = "#F1E9DA"
GRAY_72 = "rgba(94,80,62,0.72)"
INK_82 = "rgba(28,25,20,0.82)"

FONT_SERIF = "Georgia"    # slide 平台需系统字体 · Georgia 常见
FONT_SANS = "Inter"       # Inter 可能没有 · fallback 系统
FONT_SANS_FB = "思源黑体" # 飞书默认 · 最保险
FONT_SERIF_FB = "思源宋体"

# ═════════════════════════════════════════════════════════════════
# canvas 映射: SVG 900×336 → Slide 960×540
# ═════════════════════════════════════════════════════════════════

CANVAS_W = 960
CANVAS_H = 540

# SVG body 中心 (450, 168) → slide 中心 (480, 270)
DX_DEFAULT = 30
DY_DEFAULT = 102


def s2l_x(x_svg: float, dx: float = DX_DEFAULT) -> float:
    """SVG x → slide x."""
    return x_svg + dx


def s2l_y(y_svg: float, dy: float = DY_DEFAULT) -> float:
    """SVG y → slide y."""
    return y_svg + dy


# ═════════════════════════════════════════════════════════════════
# color helpers
# ═════════════════════════════════════════════════════════════════

def hex_to_rgb(hex_color: str) -> str:
    """#RRGGBB → rgb(r,g,b) · slide color 属性用."""
    h = hex_color.lstrip("#")
    r, g, b = int(h[:2], 16), int(h[2:4], 16), int(h[4:6], 16)
    return f"rgb({r},{g},{b})"


def hex_to_rgba(hex_color: str, alpha: float) -> str:
    """#RRGGBB + alpha → rgba(r,g,b,a)."""
    h = hex_color.lstrip("#")
    r, g, b = int(h[:2], 16), int(h[2:4], 16), int(h[4:6], 16)
    return f"rgba({r},{g},{b},{alpha:.2f})"


def hue_rgb(hue: str) -> str:
    """hue key → rgb() string."""
    return hex_to_rgb(HUE_HEX.get(hue, HUE_HEX["rust"]))


def hue_rgba(hue: str, alpha: float) -> str:
    """hue key + alpha → rgba() string."""
    return hex_to_rgba(HUE_HEX.get(hue, HUE_HEX["rust"]), alpha)


# ═════════════════════════════════════════════════════════════════
# XML escape
# ═════════════════════════════════════════════════════════════════

def esc(s: str) -> str:
    return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")


# ═════════════════════════════════════════════════════════════════
# Slide-native primitives
# ═════════════════════════════════════════════════════════════════

def chip_pill_lark(x_svg: float, y_svg: float, w: float, h: float, *,
                    label: str, hue: str = "rust",
                    dx: float = DX_DEFAULT, dy: float = DY_DEFAULT) -> str:
    """pill chip · slide-full-round-rect + text 居中."""
    x = s2l_x(x_svg, dx)
    y = s2l_y(y_svg, dy)
    c_rgb = hue_rgb(hue)
    tint = hue_rgba(hue, 0.12)
    return (
        f'<shape type="slides-full-round-rect" topLeftX="{x}" topLeftY="{y}" '
        f'width="{w}" height="{h}">'
        f'<fill><fillColor color="{tint}"/></fill>'
        f'<border color="{c_rgb}" width="1"/>'
        f'<content textType="body" fontSize="11" textAlign="center" verticalAlign="middle">'
        f'<p>{esc(label)}</p></content></shape>'
    )


def rect_card_lark(x_svg: float, y_svg: float, w: float, h: float, *,
                    title: str = "", sub: str = "",
                    hue: str = "rust", rx: int = 6,
                    fill_alpha: float = 0.14,
                    dx: float = DX_DEFAULT, dy: float = DY_DEFAULT) -> str:
    """三级 card · rect + tint fill + border + title + sub."""
    x = s2l_x(x_svg, dx)
    y = s2l_y(y_svg, dy)
    c_rgb = hue_rgb(hue)
    tint = hue_rgba(hue, fill_alpha)
    inner = ""
    if title:
        inner += f'<p><span bold="true" fontSize="12">{esc(title)}</span></p>'
    if sub:
        inner += f'<p><span fontSize="9" color="{c_rgb}">{esc(sub)}</span></p>'
    return (
        f'<shape type="rect" topLeftX="{x}" topLeftY="{y}" '
        f'width="{w}" height="{h}" presetHandlers="{rx}">'
        f'<fill><fillColor color="{tint}"/></fill>'
        f'<border color="{c_rgb}" width="1"/>'
        f'<content textType="body" textAlign="center" verticalAlign="middle">'
        f'{inner}</content></shape>'
    )


def hub_rect_lark(x_svg: float, y_svg: float, w: float, h: float, *,
                   name: str = "", kicker: str = "CORE",
                   stat: str = "", stat_note: str = "",
                   dark: bool = True,
                   dx: float = DX_DEFAULT, dy: float = DY_DEFAULT) -> str:
    """hub · 深底 rect + gold kicker + name + stat."""
    x = s2l_x(x_svg, dx)
    y = s2l_y(y_svg, dy)
    rust_rgb = hue_rgb("rust")
    gold_rgb = hue_rgb("gold_p")
    ink_rgba = hue_rgba(HUE_HEX["rust"].replace("#", "#"), 1)  # not used
    bg_color = "rgb(28,25,20)" if dark else "rgb(241,233,218)"
    text_color = "rgb(241,233,218)" if dark else "rgb(28,25,20)"
    inner_parts = []
    if kicker:
        inner_parts.append(
            f'<p><span fontSize="8" color="{gold_rgb}" bold="true">{esc(kicker)}</span></p>'
        )
    if name:
        inner_parts.append(
            f'<p><span fontSize="14" color="{text_color}" bold="true">{esc(name)}</span></p>'
        )
    if stat:
        stat_line = f'<span fontSize="12" color="{gold_rgb}" bold="true">{esc(stat)} </span>'
        if stat_note:
            stat_line += f'<span fontSize="8" color="rgba(241,233,218,0.72)" bold="true">{esc(stat_note)}</span>'
        inner_parts.append(f'<p>{stat_line}</p>')
    inner = "".join(inner_parts)
    return (
        f'<shape type="rect" topLeftX="{x}" topLeftY="{y}" '
        f'width="{w}" height="{h}" presetHandlers="8">'
        f'<fill><fillColor color="{bg_color}"/></fill>'
        f'<border color="{rust_rgb}" width="2"/>'
        f'<content textType="body" textAlign="center" verticalAlign="middle">'
        f'{inner}</content></shape>'
    )


def line_lark(x1_svg: float, y1_svg: float, x2_svg: float, y2_svg: float, *,
              hue: str = "rust", width: int = 2,
              arrow_end: bool = False, dashed: bool = False,
              dx: float = DX_DEFAULT, dy: float = DY_DEFAULT) -> str:
    """slide 原生 line · 骨干或 whisker."""
    x1 = s2l_x(x1_svg, dx)
    y1 = s2l_y(y1_svg, dy)
    x2 = s2l_x(x2_svg, dx)
    y2 = s2l_y(y2_svg, dy)
    c_rgb = hue_rgb(hue)
    arrow_attr = '<endArrow type="solid-triangle" widthScale="sm"/>' if arrow_end else ''
    # dashed 属性飞书 line 不支持 · 忽略
    return (
        f'<line startX="{x1}" startY="{y1}" endX="{x2}" endY="{y2}">'
        f'<border color="{c_rgb}" width="{width}"/>'
        f'{arrow_attr}</line>'
    )


def curve_lark(x1_svg: float, y1_svg: float, x2_svg: float, y2_svg: float, *,
               hue: str = "rust", width: int = 2,
               segments: int = 3, arrow_end: bool = False,
               dx: float = DX_DEFAULT, dy: float = DY_DEFAULT) -> str:
    """slide 原生 curved-connector · 可编辑弧线连接.

    输入起终点 (SVG 坐标) · 内部用 polyline type="curved-connectorN" 表达.
    polyline 用外接矩形 · 默认从左上到右下 · 用 flipX/flipY 换走向.

    segments: 2..5 · 曲线段数 · 越多越弯 · 默认 3.

    注意 slide 的 curved-connector 是"折角带弧"式曲线 · 不是任意 bezier ·
    但比直线 + 折线 (bent-connector) 更平滑 · 服务端可编辑拐点。
    """
    segments = max(2, min(5, segments))
    x1 = s2l_x(x1_svg, dx)
    y1 = s2l_y(y1_svg, dy)
    x2 = s2l_x(x2_svg, dx)
    y2 = s2l_y(y2_svg, dy)
    # bbox
    top_x = min(x1, x2)
    top_y = min(y1, y2)
    w = abs(x2 - x1)
    h = abs(y2 - y1)
    if w < 1: w = 1
    if h < 1: h = 1
    # flip 决定连线方向
    # default: 从 (top_x, top_y) [左上] 到 (top_x+w, top_y+h) [右下]
    # 起点在左下需 flipY · 起点在右上需 flipX · 起点在右下需 flipX+flipY
    flip_x = "true" if x1 > x2 else "false"
    flip_y = "true" if y1 > y2 else "false"
    c_rgb = hue_rgb(hue)
    arrow_attr = '<endArrow type="solid-triangle" widthScale="sm"/>' if arrow_end else ''
    flip_attrs = ""
    if flip_x == "true":
        flip_attrs += ' flipX="true"'
    if flip_y == "true":
        flip_attrs += ' flipY="true"'
    return (
        f'<polyline type="curved-connector{segments}" '
        f'topLeftX="{top_x}" topLeftY="{top_y}" '
        f'width="{w}" height="{h}"{flip_attrs}>'
        f'<border color="{c_rgb}" width="{width}"/>'
        f'{arrow_attr}</polyline>'
    )


def elbow_lark(x1_svg: float, y1_svg: float, x2_svg: float, y2_svg: float, *,
               hue: str = "rust", width: int = 2,
               segments: int = 3, arrow_end: bool = False,
               dx: float = DX_DEFAULT, dy: float = DY_DEFAULT) -> str:
    """slide 原生 bent-connector · 直角折线 · 用于 DAG edge 之类."""
    segments = max(2, min(5, segments))
    x1 = s2l_x(x1_svg, dx)
    y1 = s2l_y(y1_svg, dy)
    x2 = s2l_x(x2_svg, dx)
    y2 = s2l_y(y2_svg, dy)
    top_x = min(x1, x2)
    top_y = min(y1, y2)
    w = max(1, abs(x2 - x1))
    h = max(1, abs(y2 - y1))
    flip_attrs = ""
    if x1 > x2:
        flip_attrs += ' flipX="true"'
    if y1 > y2:
        flip_attrs += ' flipY="true"'
    c_rgb = hue_rgb(hue)
    arrow_attr = '<endArrow type="solid-triangle" widthScale="sm"/>' if arrow_end else ''
    return (
        f'<polyline type="bent-connector{segments}" '
        f'topLeftX="{top_x}" topLeftY="{top_y}" '
        f'width="{w}" height="{h}"{flip_attrs}>'
        f'<border color="{c_rgb}" width="{width}"/>'
        f'{arrow_attr}</polyline>'
    )


def text_lark(x_svg: float, y_svg: float, w: float, h: float, *,
              text: str, size: int = 11, bold: bool = False,
              italic: bool = False, color: str = INK,
              anchor: str = "left", family: str = FONT_SANS_FB,
              wrap: bool = True, auto_fit: bool = True,
              dx: float = DX_DEFAULT, dy: float = DY_DEFAULT) -> str:
    """slide 原生 text shape · 默认 wrap+autoFit 允许 shrink to fit."""
    x = s2l_x(x_svg, dx)
    y = s2l_y(y_svg, dy)
    c = color if color.startswith("rgb") else hex_to_rgb(color)
    text_align = {"left": "left", "middle": "center", "right": "right",
                   "center": "center"}.get(anchor, "left")
    attrs = f'fontSize="{size}" color="{c}" textAlign="{text_align}"'
    if bold:
        attrs += ' bold="true"'
    if italic:
        attrs += ' italic="true"'
    if wrap:
        attrs += ' wrap="true"'
    if auto_fit:
        attrs += ' autoFit="normal-auto-fit"'
    return (
        f'<shape type="text" topLeftX="{x}" topLeftY="{y}" '
        f'width="{w}" height="{h}">'
        f'<content {attrs}><p>{esc(text)}</p></content></shape>'
    )


def circle_badge_lark(cx_svg: float, cy_svg: float, r: float, *,
                       label: str = "", hue: str = "rust",
                       filled: bool = True,
                       dx: float = DX_DEFAULT, dy: float = DY_DEFAULT) -> str:
    """circle badge · numeral / P disc / kolb badge."""
    x = s2l_x(cx_svg - r, dx)
    y = s2l_y(cy_svg - r, dy)
    c_rgb = hue_rgb(hue)
    if filled:
        fill_color = c_rgb
        text_color = "rgb(241,233,218)"
    else:
        fill_color = hue_rgba(hue, 0.12)
        text_color = c_rgb
    return (
        f'<shape type="ellipse" topLeftX="{x}" topLeftY="{y}" '
        f'width="{r*2}" height="{r*2}">'
        f'<fill><fillColor color="{fill_color}"/></fill>'
        f'<border color="{c_rgb}" width="1"/>'
        f'<content textType="body" fontSize="9" textAlign="center" verticalAlign="middle" '
        f'color="{text_color}" bold="true">'
        f'<p>{esc(label)}</p></content></shape>'
    )


# ═════════════════════════════════════════════════════════════════
# 装饰底层 embed · 保留 SVG 里的 halo/hairline/background · 底层不可编辑
# ═════════════════════════════════════════════════════════════════

def embed_decoration_lark(svg_content: str, *,
                           topLeftX: float = 40, topLeftY: float = 110,
                           width: float = 880, height: float = 328) -> str:
    """把一段 SVG(装饰层)用 <embed> 塞进 slide 作为底层背景.

    自动 dedup: 移除具有完全相同 bbox 的重复 <rect> · 满足 lint bbox_overlap 规则.
    """
    svg_content = _dedup_overlapping_rects(svg_content)
    return (
        f'<embed topLeftX="{topLeftX}" topLeftY="{topLeftY}" '
        f'width="{width}" height="{height}">{svg_content}</embed>'
    )


def _dedup_overlapping_rects(svg_content: str) -> str:
    """扫描 SVG 里的 <rect> / <circle> · 移除后续 bbox 完全相同的重复 shape · 避免 lint bbox_overlap."""
    import re
    rect_pattern = re.compile(r'<rect\s+([^/>]*?)/>')
    circle_pattern = re.compile(r'<circle\s+([^/>]*?)/>')

    seen_rect = set()

    def rect_replacer(m):
        attrs = m.group(1)
        vals = {}
        for a in ('x', 'y', 'width', 'height'):
            am = re.search(rf'{a}="([^"]+)"', attrs)
            if am:
                vals[a] = am.group(1)
        if 'x' not in vals:
            return m.group(0)
        key = (vals.get('x'), vals.get('y'), vals.get('width'), vals.get('height'))
        if key in seen_rect:
            return ''
        seen_rect.add(key)
        return m.group(0)

    svg_content = rect_pattern.sub(rect_replacer, svg_content)

    seen_circle = set()

    def circle_replacer(m):
        attrs = m.group(1)
        vals = {}
        for a in ('cx', 'cy', 'r'):
            am = re.search(rf'{a}="([^"]+)"', attrs)
            if am:
                vals[a] = am.group(1)
        if 'cx' not in vals:
            return m.group(0)
        key = (vals.get('cx'), vals.get('cy'), vals.get('r'))
        if key in seen_circle:
            return ''
        seen_circle.add(key)
        return m.group(0)

    svg_content = circle_pattern.sub(circle_replacer, svg_content)

    return svg_content


def make_background_rect_lark(color: str = BONE) -> str:
    """给整页刷 cream 背景色 · slide 默认白 · 我们要 cream."""
    return (
        f'<shape type="rect" topLeftX="0" topLeftY="0" width="960" height="540">'
        f'<fill><fillColor color="{hex_to_rgb(color)}"/></fill>'
        f'<border color="{hex_to_rgb(color)}" width="0"/>'
        f'</shape>'
    )

def chrome_title_lark(title: str, subtitle: str = "",
                       encoding_right: str = "") -> str:
    """顶部 slide-native chrome · title + subtitle + top-right encoding."""
    parts = []
    parts.append(
        f'<shape type="text" topLeftX="40" topLeftY="30" width="880" height="40">'
        f'<content textType="title" fontSize="20" bold="true">'
        f'<p>{esc(title)}</p></content></shape>'
    )
    if subtitle:
        parts.append(
            f'<shape type="text" topLeftX="40" topLeftY="70" width="700" height="30">'
            f'<content fontSize="11" color="{GRAY_72}"><p>{esc(subtitle)}</p></content></shape>'
        )
    if encoding_right:
        parts.append(
            f'<shape type="text" topLeftX="740" topLeftY="70" width="180" height="30">'
            f'<content fontSize="10" color="{GRAY_72}" textAlign="right" italic="true">'
            f'<p>{esc(encoding_right)}</p></content></shape>'
        )
    return "".join(parts)


def chrome_footer_lark(read_lines: list[str], source: str = "") -> str:
    """底部 slide-native chrome · READ 段 + source.

    read_lines 单行安全长度 ~110 chars @ fontSize=9 · 若过长会因 wrap 导致 lint 报警.
    """
    parts = []
    y = 490
    parts.append(
        f'<shape type="text" topLeftX="40" topLeftY="{y}" width="80" height="14">'
        f'<content fontSize="9" color="{GRAY_72}" bold="true"><p>READ</p></content></shape>'
    )
    # 每行 gap 14 · 从 y=504 · 到 y=532 为止 · autoFit shrink to fit
    for i, line in enumerate(read_lines[:2]):
        line_y = y + 14 + i * 14
        parts.append(
            f'<shape type="text" topLeftX="40" topLeftY="{line_y}" width="600" height="14">'
            f'<content fontSize="9" color="{INK_82}" wrap="true" autoFit="normal-auto-fit"><p>{esc(line)}</p></content></shape>'
        )
    if source:
        parts.append(
            f'<shape type="text" topLeftX="650" topLeftY="510" width="270" height="20">'
            f'<content fontSize="9" color="{GRAY_72}" textAlign="right" bold="true" wrap="true" autoFit="normal-auto-fit">'
            f'<p>{esc(source)}</p></content></shape>'
        )
    return "".join(parts)


# ═════════════════════════════════════════════════════════════════
# Page wrapper
# ═════════════════════════════════════════════════════════════════

SML_NS = 'xmlns="https://www.larkoffice.com/sml/2.0"'


def wrap_slide(inner_xml: str) -> str:
    """把一堆 shape/line xml 包成完整 <slide>."""
    return f'<slide {SML_NS}><data>{inner_xml}</data></slide>'


__all__ = [
    "HUE_HEX", "INK", "BONE", "GRAY_72", "INK_82",
    "FONT_SERIF_FB", "FONT_SANS_FB",
    "s2l_x", "s2l_y", "hex_to_rgb", "hex_to_rgba", "hue_rgb", "hue_rgba", "esc",
    "chip_pill_lark", "rect_card_lark", "hub_rect_lark",
    "line_lark", "text_lark", "circle_badge_lark",
    "chrome_title_lark", "chrome_footer_lark",
    "wrap_slide", "DX_DEFAULT", "DY_DEFAULT",
]
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall