Skip to content

Commit

Permalink
Manually show a and k on property docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasaglia authored Aug 6, 2024
1 parent afb9e63 commit b4d561b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/specs/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ In the following example, the ball moves left and right, on the background you c
Animatable {link:values/vector}.

{schema_object:properties/vector-property}
<tr><td>`a`</td><td>{link:values/int-boolean}</td><td>Animated</td><td>Whether the property is animated</td></tr>
<tr><td>`k`</td>
<td>{link:values/vector} or `array`</td>
<td>Value or Keyframes</td>
<td>When it's not animated, `k` will contain the value directly. When animated, `k` will be an array of keyframes.</td>
</tr>


<h4 id="vector-keyframe">Vector Keyframe</h4>
Expand All @@ -108,13 +114,25 @@ Note that when animated it uses {link:properties/vector-keyframe:Vector Keyframe
so instead of scalars keyframes have arrays with a single values.

{schema_object:properties/scalar-property}
<tr><td>`a`</td><td>{link:values/int-boolean}</td><td>Animated</td><td>Whether the property is animated</td></tr>
<tr><td>`k`</td>
<td>`number` or `array`</td>
<td>Value or Keyframes</td>
<td>When it's not animated, `k` will contain the value directly. When animated, `k` will be an array of keyframes.</td>
</tr>


<h3 id="position-property">Position</h3>

Animatable 2D {link:values/vector} with optional spatial tangents.

{schema_object:properties/position-property}
<tr><td>`a`</td><td>{link:values/int-boolean}</td><td>Animated</td><td>Whether the property is animated</td></tr>
<tr><td>`k`</td>
<td>{link:values/vector} or `array`</td>
<td>Value or Keyframes</td>
<td>When it's not animated, `k` will contain the value directly. When animated, `k` will be an array of keyframes.</td>
</tr>


<h4 id="position-keyframe">Position Keyframe</h4>
Expand All @@ -135,6 +153,12 @@ Animatable 2D {link:values/vector} with optional spatial tangents.
Animatable {link:values/bezier}.

{schema_object:properties/bezier-property}
<tr><td>`a`</td><td>{link:values/int-boolean}</td><td>Animated</td><td>Whether the property is animated</td></tr>
<tr><td>`k`</td>
<td>{link:values/bezier} or `array`</td>
<td>Value or Keyframes</td>
<td>When it's not animated, `k` will contain the value directly. When animated, `k` will be an array of keyframes.</td>
</tr>


<h4 id="bezier-keyframe">Bezier Shape Keyframe</h4>
Expand All @@ -148,6 +172,12 @@ Animatable {link:values/bezier}.
Animatable {link:values/color}.

{schema_object:properties/color-property}
<tr><td>`a`</td><td>{link:values/int-boolean}</td><td>Animated</td><td>Whether the property is animated</td></tr>
<tr><td>`k`</td>
<td>{link:values/color} or `array`</td>
<td>Value or Keyframes</td>
<td>When it's not animated, `k` will contain the value directly. When animated, `k` will be an array of keyframes.</td>
</tr>


<h4 id="color-keyframe">Color Keyframe</h4>
Expand All @@ -161,6 +191,12 @@ Animatable {link:values/color}.
Animatable {link:values/gradient}.

{schema_object:properties/gradient-property}
<tr><td>`k.a`</td><td>{link:values/int-boolean}</td><td>Animated</td><td>Whether the property is animated</td></tr>
<tr><td>`k.k`</td>
<td>{link:values/gradient} or `array`</td>
<td>Value or Keyframes</td>
<td>When it's not animated, `k` will contain the value directly. When animated, `k` will be an array of keyframes.</td>
</tr>

Color count is not animatable.

Expand Down
3 changes: 3 additions & 0 deletions schema/properties/gradient-property.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"type": "number"
},
"k": {
"type": "object",
"title": "Gradient stops",
"description": "Animatable vector representing the gradient stops",
"oneOf": [
{
"$comment": "Not animated",
Expand Down
25 changes: 25 additions & 0 deletions tools/lottie_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ def run(self, parent, blocks):
graph = inheritance.inheritance_graph(type)
details.append(graph)

if not has_own_props and blocks and (block_to_html(self, blocks[0]) or "").startswith("<tr"):
has_own_props = True

if has_own_props:
table = etree.SubElement(div, "table")
thead = etree.SubElement(etree.SubElement(table, "thead"), "tr")
Expand All @@ -328,6 +331,20 @@ def run(self, parent, blocks):
for name, prop in prop_dict.items():
self.prop_row(name, prop, tbody)

# Append any trailing <tr> to the table
last_tr = -1
for i, block in enumerate(blocks):
if block == "":
continue
next_html = block_to_html(self, block)
if not next_html or not next_html.startswith("<tr"):
break
last_tr = i
tbody.append(etree_fromstring(next_html))

for i in range(last_tr + 1):
blocks.pop(0)

return True

def prop_row(self, name, prop: type_info.Property, tbody):
Expand Down Expand Up @@ -984,6 +1001,14 @@ def handleMatch(self, match, data):
return span, match.start(0), match.end(0)


def block_to_html(block_processor, block):
match = HTML_PLACEHOLDER_RE.match(block)
if match:
index = int(match.group(1))
return block_processor.parser.md.htmlStash.rawHtmlBlocks[index]
return None


def pop_script_block(block_processor, blocks):
script_match = HTML_PLACEHOLDER_RE.match(blocks[0])
if script_match:
Expand Down
3 changes: 3 additions & 0 deletions tools/schema_tools/type_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def __init__(self, type_system: TypeSystem, schema: Schema):

def resolve_type(self, schema: Schema):
if "oneOf" in schema:
local_type = schema.get("type", None)
if local_type is not None:
return local_type
return [self.resolve_type(choice) for choice in schema / "oneOf"]
if "$ref" in schema:
return self.type_system.types[schema["$ref"]]
Expand Down

0 comments on commit b4d561b

Please sign in to comment.