dymokomi/luced-2d
Source of release 0.5.1
0.5.1 / src / script_api_text.luc
## Generated by tools/embed_api.py from scripting/; do not edit.
## The scripting API module every script imports as `luced`.
pub let api_source: str = "## luced-2d's scripting API, as Maya's is to its commands: every call here is\n## one editor action, done in the open document as the script runs, and the\n## whole run is one undo step. A script is a Luce program — `import luced`, a\n## `main` — run by the editor's Luce interpreter in a sandbox folder.\n##\n## Colors are sRGB, 0..1 a channel. Positions and sizes are document pixels,\n## (0, 0) the top-left corner. Layers count from 0 at the bottom of the stack.\n## Queries (`document_width`, `layer_names`, ...) tell the document as it was when the\n## script started; what the script itself changes is not seen by them.\n##\n## How it works: each call prints one line, `@l2d` and the action's name and\n## fields separated by tabs, which the editor reads and does. Any other line\n## a script prints goes to the script console.\nimport document\n\nfunc send(action: str, fields: list[str]):\n var message = \"@l2d \" + action\n for field in fields:\n message = message + \"\\t\" + field.replace(\"\\\\\", \"\\\\\\\\\").replace(\"\\t\", \"\\\\t\").replace(\"\\n\", \"\\\\n\")\n print(message)\n\n# mark: What the document was =================================================================\n\n## The document's width and height in pixels.\npub func document_width() -> int:\n return document.width()\n\npub func document_height() -> int:\n return document.height()\n\n## The layers' names, bottom to top.\npub func layer_names() -> list[str]:\n return document.layers()\n\n## The selected layer's place in the stack.\npub func selected_layer() -> int:\n return document.selected()\n\n## Whether the document blends its colors in linear light (Color Settings'\n## \"Blend RGB Colors Using Gamma 1.0\"); false: as sRGB values, Photoshop's default.\npub func linear_blend() -> bool:\n return document.linear_blend()\n\n## The open document's file, or \"\" when it was never saved.\npub func document_path() -> str:\n return document.path()\n\n# mark: Documents ============================================================================\n\n## A new empty document of `width` by `height` pixels in its own tab.\npub func new_document(width: int, height: int):\n send(\"new_document\", [str(width), str(height)])\n\n## Open the picture or document at `path` in its own tab.\npub func open(path: str):\n send(\"open\", [path])\n\n## Save the document at `path` (an .l2d keeps its layers).\npub func save(path: str):\n send(\"save\", [path])\n\n## Export the flattened picture: PNG or JPEG by the name's extension;\n## `quality` 1..100 for JPEG.\npub func export(path: str, quality: int = 90):\n send(\"export\", [path, str(quality)])\n\n## Place a picture file as a new layer, centred.\npub func place(path: str):\n send(\"place\", [path])\n\n## Undo the last step, or redo it.\npub func undo():\n send(\"undo\", [])\n\npub func redo():\n send(\"redo\", [])\n\n## Any menu command by its id, as the Settings dialog's shortcut list names\n## them (\"flip_horizontal\", \"merge_down\", \"inverse\", ...), headless too.\n## One that opens a dialog opens it; the parametric calls here are for those.\npub func run(command: str):\n send(\"run\", [command])\n\n# mark: Layers ===============================================================================\n\n## A new empty layer named `name` above the selected one, selected.\npub func add_layer(name: str):\n send(\"add_layer\", [name])\n\n## Select the layer at `index` (0 the bottom).\npub func select_layer(index: int):\n send(\"select_layer\", [str(index)])\n\n## Select the topmost layer called `name`.\npub func select_layer_named(name: str):\n send(\"select_layer_named\", [name])\n\npub func rename_layer(name: str):\n send(\"rename_layer\", [name])\n\npub func delete_layer():\n send(\"delete_layer\", [])\n\npub func duplicate_layer():\n send(\"duplicate_layer\", [])\n\npub func merge_down():\n send(\"merge_down\", [])\n\n## Move the selected layer `steps` places up the stack (negative: down).\npub func move_layer_up(steps: int):\n send(\"reorder\", [str(steps)])\n\n## The selected layer's opacity, 0..1.\npub func set_opacity(opacity: float):\n send(\"set_opacity\", [str(opacity)])\n\n## The selected layer's blend mode by Photoshop's name (\"Multiply\", \"Screen\", ...).\npub func set_blend(mode: str):\n send(\"set_blend\", [mode])\n\npub func set_visible(visible: bool):\n send(\"set_visible\", [str(visible)])\n\n## Move the selected layer's pixels by (`dx`, `dy`).\npub func move_by(dx: int, dy: int):\n send(\"move_by\", [str(dx), str(dy)])\n\n## A mask on the selected layer revealing the selection (everything without one).\npub func add_mask():\n send(\"add_mask\", [])\n\n# mark: Painting =============================================================================\n\n## The foreground color, and the background's.\npub func set_color(red: float, green: float, blue: float):\n send(\"set_color\", [str(red), str(green), str(blue)])\n\npub func set_background(red: float, green: float, blue: float):\n send(\"set_background\", [str(red), str(green), str(blue)])\n\n## The brush: its diameter in pixels, hardness and opacity 0..1.\npub func set_brush(size: float, hardness: float = 0.75, opacity: float = 1.0):\n send(\"set_brush\", [str(size), str(hardness), str(opacity)])\n\n## Paint one stroke through `points`, x and y pairs; `erase` erases instead.\npub func stroke(points: list[float], erase: bool = false):\n var fields = [str(erase)]\n for value in points:\n fields.append(str(value))\n send(\"stroke\", fields)\n\n## A straight stroke from (`x0`, `y0`) to (`x1`, `y1`).\npub func line(x0: float, y0: float, x1: float, y1: float):\n stroke([x0, y0, x1, y1])\n\n## Fill the selection (the whole layer without one) with the foreground color.\npub func fill():\n send(\"fill\", [])\n\n## Erase the selection (the whole layer without one).\npub func clear():\n send(\"clear\", [])\n\n## A gradient from the foreground color at (`x0`, `y0`) to the background at\n## (`x1`, `y1`); `radial` for a circle about the start.\npub func gradient(x0: float, y0: float, x1: float, y1: float, radial: bool = false):\n send(\"gradient\", [str(x0), str(y0), str(x1), str(y1), str(radial)])\n\n## A text layer of `words` at (`x`, `y`), `size` points, in the foreground color.\npub func text(x: float, y: float, words: str, size: float = 48.0):\n send(\"text\", [str(x), str(y), words, str(size)])\n\n# mark: Selections ===========================================================================\n\n## Select a rectangle or an ellipse; `mode` 0 new, 1 add, 2 subtract, 3 intersect.\npub func select_rectangle(x: int, y: int, width: int, height: int, mode: int = 0):\n send(\"select_rectangle\", [str(x), str(y), str(width), str(height), str(mode)])\n\npub func select_ellipse(x: int, y: int, width: int, height: int, mode: int = 0):\n send(\"select_ellipse\", [str(x), str(y), str(width), str(height), str(mode)])\n\npub func select_all():\n send(\"select_all\", [])\n\npub func deselect():\n send(\"deselect\", [])\n\npub func invert_selection():\n send(\"invert_selection\", [])\n\n## Select › Modify: grow (positive `pixels`) or shrink (negative) the\n## selection, then feather its edge by `feather` pixels.\npub func modify_selection(pixels: int, feather: int = 0):\n send(\"modify_selection\", [str(pixels), str(feather)])\n\n## Quick Mask on (`on`) or off: while on, painting edits the selection\n## (black masks, white selects); turning it off makes that the selection.\npub func quick_mask(on: bool = true):\n send(\"quick_mask\", [str(on)])\n\n## Select › Save Selection: the selection kept as alpha channel `name`.\npub func save_selection(name: str):\n send(\"save_selection\", [name])\n\n## Select › Load Selection: alpha channel `name` as the selection; `mode` 0\n## new, 1 add, 2 subtract, 3 intersect.\npub func load_selection(name: str, mode: int = 0):\n send(\"load_selection\", [name, str(mode)])\n\n## Delete alpha channel `name`.\npub func delete_channel(name: str):\n send(\"delete_channel\", [name])\n\n## Select › Modify › Border: a band `width` pixels wide along the selection's edge.\npub func border_selection(width: int):\n send(\"border_selection\", [str(width)])\n\n## Select › Modify › Smooth: corners rounded and specks dropped over `radius` pixels.\npub func smooth_selection(radius: int):\n send(\"smooth_selection\", [str(radius)])\n\n## Select › Grow (`contiguous`) or Similar: more of the colors the selection\n## covers, within `tolerance` (0..255, as the magic wand's).\npub func grow_selection(contiguous: bool = true, tolerance: float = 32.0):\n send(\"grow_selection\", [str(contiguous), str(tolerance)])\n\n## Select › Transform Selection in one go: the outline scaled, turned by\n## `angle` degrees about (`pivot_x`, `pivot_y`) and moved by (`dx`, `dy`).\npub func transform_selection(scale_x: float, scale_y: float, angle: float = 0.0, dx: float = 0.0, dy: float = 0.0, pivot_x: float = 0.0, pivot_y: float = 0.0):\n send(\"transform_selection\", [str(scale_x), str(scale_y), str(angle), str(dx), str(dy), str(pivot_x), str(pivot_y)])\n\n## The Magnetic Lasso: its first anchor at the first of `points` (x, y\n## pairs, document pixels), a click at each of the others, then closed back\n## to the start along the edge; `mode` 0 new, 1 add, 2 subtract, 3 intersect.\npub func magnetic_lasso(points: list[float], width: float = 10.0, contrast: float = 10.0, frequency: int = 57, mode: int = 0):\n var fields = [str(width), str(contrast), str(frequency), str(mode)]\n for value in points:\n fields = fields + [str(value)]\n send(\"magnetic_lasso\", fields)\n\n## Select › Select and Mask in one go: edge detection `radius` (0..250 px),\n## `smooth` (0..100), `feather` (0..250 px), `contrast` (0..100%) and\n## `shift` edge (-100..100%), as one step.\npub func select_and_mask(radius: int = 0, smooth: int = 0, feather: int = 0, contrast: float = 0.0, shift: float = 0.0):\n send(\"select_and_mask\", [str(radius), str(smooth), str(feather), str(contrast), str(shift)])\n\n## Select › Color Range. `range` is \"Sampled Colors\" (the sRGB triples in\n## `colors`, within `fuzziness` 0..200), \"Reds\", \"Yellows\", \"Greens\", \"Cyans\",\n## \"Blues\", \"Magentas\", \"Highlights\", \"Midtones\" or \"Shadows\"; `invert`\n## selects the rest instead.\npub func select_color_range(range: str = \"Sampled Colors\", colors: list[float]? = none, fuzziness: float = 40.0, invert: bool = false):\n let names = [\"Sampled Colors\", \"Reds\", \"Yellows\", \"Greens\", \"Cyans\", \"Blues\", \"Magentas\", \"Highlights\", \"Midtones\", \"Shadows\"]\n var index = 0\n while index < names.length and names[index] != range:\n index += 1\n var fields = [str(index), str(fuzziness), str(invert)]\n let sampled = colors else []\n var at = 0\n while at + 2 < sampled.length:\n fields = fields + [str(sampled[at]), str(sampled[at + 1]), str(sampled[at + 2]), \"false\"]\n at += 3\n send(\"select_color_range\", fields)\n\n# mark: Adjustments and filters ==============================================================\n\n## Adjust the selected layer's pixels once by adjustment `name` (\"Levels\",\n## \"Hue / Saturation\", \"Exposure\", \"Vignette\", ...) with its settings in the\n## units its dialog shows, in its dialog's order; fewer keep the defaults.\npub func adjust(name: str, settings: list[float]? = none):\n var fields = [name]\n for value in settings else []:\n fields.append(str(value))\n send(\"adjust\", fields)\n\n## The same adjustment as a live adjustment layer above the selected layer.\npub func add_adjustment_layer(name: str, settings: list[float]? = none):\n var fields = [name]\n for value in settings else []:\n fields.append(str(value))\n send(\"adjustment_layer\", fields)\n\n## Filter `name` (\"Gaussian Blur\", \"Motion Blur\", \"Lens Correction\", \"Bloom\",\n## \"Tonal Contrast\", \"Add Noise\") with its settings as its dialog shows them.\npub func filter(name: str, settings: list[float]? = none):\n var fields = [name]\n for value in settings else []:\n fields.append(str(value))\n send(\"filter\", fields)\n\n# mark: Transforms ===========================================================================\n\n## Edit › Transform › Distort in one go: the selected layer's painted box (the\n## selection's, whose pixels then float) with its corners moved to `corners`,\n## x and y pairs clockwise from the top-left, in perspective.\npub func distort(corners: list[float]):\n var fields: list[str] = []\n for value in corners:\n fields.append(str(value))\n send(\"distort\", fields)\n\n## Edit › Transform › Skew in one go: the box slanted `horizontal` degrees\n## (its top to the right) and `vertical` degrees (its right side down) about its middle.\npub func skew(horizontal: float, vertical: float = 0.0):\n send(\"skew\", [str(horizontal), str(vertical)])\n\n## Edit › Transform › Perspective in one go: the box's top narrowed by\n## `amount` of its width (negative widens it), or with `vertical` its right\n## side by that much of its height; the opposite side stays.\npub func perspective(amount: float, vertical: bool = false):\n send(\"perspective\", [str(amount), str(vertical)])\n\n## Edit › Transform › Warp in one go with a style — \"Arc\", \"Arch\", \"Bulge\",\n## \"Flag\", \"Wave\" or \"Rise\" — bent by `bend` (-1..1).\npub func warp(style: str = \"Arc\", bend: float = 0.5):\n send(\"warp\", [style, str(bend)])\n\n## Edit › Transform › Warp by its patch: sixteen x, y points row by row over\n## the layer's painted box, as the Warp mesh has them (corners 0, 3, 12, 15).\npub func warp_points(points: list[float]):\n var fields: list[str] = []\n for value in points:\n fields.append(str(value))\n send(\"warp_points\", fields)\n\n## Edit › Puppet Warp in one go: a pin for each four of `pins` — put at the\n## first x, y and dragged to the second — the picture bent about them;\n## `density` 0 fewer, 1 normal, 2 more mesh points.\npub func puppet_warp(pins: list[float], density: int = 1):\n var fields = [str(density)]\n for value in pins:\n fields.append(str(value))\n send(\"puppet_warp\", fields)\n\n# mark: Vectors ==============================================================================\n\n## A vector element on the selected layer — `kind` \"rectangle\", \"ellipse\",\n## \"line\" or \"polygon\" — in the box, filled with the foreground color and\n## stroked as the shape tools' header says (a line is stroked with the\n## foreground). It goes on a new vector layer unless the selected layer is\n## one, or holds nothing.\npub func add_vector(kind: str, x: float, y: float, width: float, height: float):\n send(\"add_vector\", [kind, str(x), str(y), str(width), str(height)])\n\n## A pen path through `points` (x, y pairs; corner anchors), closed back to\n## the first unless `closed` is false, placed as `add_vector`.\npub func add_path(points: list[float], closed: bool = true):\n var fields = [str(closed)]\n for value in points:\n fields.append(str(value))\n send(\"add_path\", fields)\n\n## The Vector panel's New Path: an empty path called `name`, active, for the Pen.\npub func new_path(name: str):\n send(\"new_path\", [name])\n\n## The selected layer's element at `index` (0 the bottom) made active, so a\n## move or transform acts on it alone; -1 for none, the whole layer.\npub func select_vector(index: int):\n send(\"select_vector\", [str(index)])\n\npub func rename_vector(index: int, name: str):\n send(\"rename_vector\", [str(index), name])\n\npub func set_vector_visible(index: int, visible: bool):\n send(\"show_vector\", [str(index), str(visible)])\n\n## Element `index` put at place `to` among the layer's elements (0 the bottom).\npub func move_vector(index: int, to: int):\n send(\"move_vector\", [str(index), str(to)])\n\npub func duplicate_vector(index: int):\n send(\"duplicate_vector\", [str(index)])\n\npub func delete_vector(index: int):\n send(\"delete_vector\", [str(index)])\n\n## Make Selection: element `index`'s outline as the selection; `mode` 0 new,\n## 1 add, 2 subtract, 3 intersect.\npub func vector_selection(index: int, mode: int = 0):\n send(\"vector_selection\", [str(index), str(mode)])\n\n## Element `index` alone scaled, turned by `angle` degrees about\n## (`pivot_x`, `pivot_y`) and moved by (`dx`, `dy`), crisp.\npub func transform_vector(index: int, scale_x: float, scale_y: float, angle: float = 0.0, dx: float = 0.0, dy: float = 0.0, pivot_x: float = 0.0, pivot_y: float = 0.0):\n send(\"transform_vector\", [str(index), str(scale_x), str(scale_y), str(angle), str(dx), str(dy), str(pivot_x), str(pivot_y)])\n\n# mark: Node graphs ==========================================================================\n\n## A new vector layer above the selected one, selected: its node graph a star\n## cloned round a circle, whose nodes are called \"star\", \"circle\", \"clone\" and\n## \"output\".\npub func new_vector_layer():\n send(\"new_vector_layer\", [])\n\n## A node of `kind` — \"Rectangle\", \"Ellipse\", \"Polygon\", \"Star\", \"Path\",\n## \"Grid\", \"Circle\", \"Line\", \"Random Scatter\", \"Points of Shape\", \"Clone\",\n## \"Transform\", \"Merge\", \"Number\", \"Random\", \"Color Gradient\" or \"Output\" — in\n## the selected vector layer's graph, called `name` from here on, at (`x`, `y`)\n## in the Node Editor.\npub func add_node(kind: str, name: str, x: float = 0.0, y: float = 0.0):\n send(\"add_node\", [kind, name, str(x), str(y)])\n\n## Node `source`'s output wired into input `input` of node `target` (its name,\n## as the node shows it — \"Shapes\", \"Points\", \"Count\" — or its number).\npub func link_nodes(source: str, target: str, input: str):\n send(\"link_nodes\", [source, target, input])\n\npub func unlink_node(target: str, input: str):\n send(\"unlink_node\", [target, input])\n\n## Setting `setting` of node `node` (as the Node Editor names it: \"Count\",\n## \"Radius\", \"Jitter Rotation\", ...); a toggle is 1 or 0.\npub func set_node(node: str, setting: str, value: float):\n send(\"set_node\", [node, setting, str(value)])\n\n## A color setting (\"Fill Color\", \"Start\", ...), sRGB 0..1 a channel.\npub func set_node_color(node: str, setting: str, red: float, green: float, blue: float):\n send(\"set_node_color\", [node, setting, str(red), str(green), str(blue)])\n\npub func delete_node(node: str):\n send(\"delete_node\", [node])\n\n# mark: The canvas ===========================================================================\n\n## Scale the whole document to `width` by `height` pixels.\npub func resize_image(width: int, height: int):\n send(\"resize_image\", [str(width), str(height)])\n\n## Change the canvas to `width` by `height`, the picture kept at the top-left\n## moved by (`x`, `y`).\npub func resize_canvas(width: int, height: int, x: int = 0, y: int = 0):\n send(\"resize_canvas\", [str(width), str(height), str(x), str(y)])\n\n## Crop to the rectangle.\npub func crop(x: int, y: int, width: int, height: int):\n send(\"crop\", [str(x), str(y), str(width), str(height)])\n\npub func flip_canvas(horizontal: bool = true):\n send(\"flip_canvas\", [str(horizontal)])\n\n## Document Settings' \"Blend RGB Colors Using Gamma 1.0\": `on` mixes colors\n## in linear light from here on; off, as sRGB values, as Photoshop does. One step.\npub func set_linear_blend(on: bool):\n send(\"set_linear_blend\", [str(on)])\n"
## The Luce grammar the Script editor highlights with.
pub let grammar_source: str = "{\n \"name\": \"Luce\",\n \"scopeName\": \"source.luce\",\n \"fileTypes\": [\"luc\", \"lucb\"],\n \"patterns\": [\n { \"include\": \"#comment\" },\n { \"include\": \"#string\" },\n { \"include\": \"#number\" },\n { \"include\": \"#constant\" },\n { \"include\": \"#keyword\" },\n { \"include\": \"#builtin-type\" },\n { \"include\": \"#type-name\" },\n { \"include\": \"#function-call\" }\n ],\n \"repository\": {\n \"comment\": {\n \"patterns\": [\n { \"match\": \"^\\\\s*#\\\\s*mark:.*$\", \"name\": \"comment.section.luce\" },\n { \"match\": \"#.*$\", \"name\": \"comment.line.number-sign.luce\" }\n ]\n },\n \"string\": {\n \"patterns\": [\n {\n \"begin\": \"[rbf]?\\\"\\\"\\\"\",\n \"end\": \"\\\"\\\"\\\"\",\n \"name\": \"string.quoted.triple.double.luce\",\n \"patterns\": [{ \"match\": \"\\\\\\\\.\" , \"name\": \"constant.character.escape.luce\" }]\n },\n {\n \"begin\": \"[rbf]?'''\",\n \"end\": \"'''\",\n \"name\": \"string.quoted.triple.single.luce\",\n \"patterns\": [{ \"match\": \"\\\\\\\\.\", \"name\": \"constant.character.escape.luce\" }]\n },\n {\n \"begin\": \"[rbf]?\\\"\",\n \"end\": \"\\\"\",\n \"name\": \"string.quoted.double.luce\",\n \"patterns\": [{ \"match\": \"\\\\\\\\.\", \"name\": \"constant.character.escape.luce\" }]\n },\n {\n \"begin\": \"[rbf]?'\",\n \"end\": \"'\",\n \"name\": \"string.quoted.single.luce\",\n \"patterns\": [{ \"match\": \"\\\\\\\\.\", \"name\": \"constant.character.escape.luce\" }]\n }\n ]\n },\n \"number\": {\n \"match\": \"\\\\b(0[xX][0-9a-fA-F_]+|0[oO][0-7_]+|0[bB][01_]+|[0-9][0-9_]*(\\\\.[0-9_]+)?([eE][+-]?[0-9]+)?)\\\\b\",\n \"name\": \"constant.numeric.luce\"\n },\n \"constant\": {\n \"match\": \"\\\\b(true|false|none)\\\\b\",\n \"name\": \"constant.language.luce\"\n },\n \"keyword\": {\n \"match\": \"\\\\b(and|as|break|catch|class|const|continue|defer|elif|else|enum|errdefer|extern|for|from|func|if|import|in|init|interface|is|let|match|mutating|new|not|or|pub|recover|return|self|spawn|static|struct|test|try|type|var|wait|while|with|alloc|free|discard)\\\\b\",\n \"name\": \"keyword.control.luce\"\n },\n \"builtin-type\": {\n \"match\": \"\\\\b(int|float|bool|str|bytes|unit|never|list|map|set|Error|ErrorCode|Weak|task|char|i8|i16|i32|i64|u8|u16|u32|u64|usize|isize|f32|f64|void)\\\\b\",\n \"name\": \"storage.type.luce\"\n },\n \"type-name\": {\n \"match\": \"\\\\b[A-Z][A-Za-z0-9_]*\\\\b\",\n \"name\": \"entity.name.type.luce\"\n },\n \"function-call\": {\n \"match\": \"\\\\b([a-z_][A-Za-z0-9_]*)\\\\s*(?=\\\\()\",\n \"name\": \"entity.name.function.luce\"\n }\n }\n}\n"