Skip to content

Commit 6fa5a91

Browse files
authored
Fix issues with the rendering tips
2 parents b01fd53 + a5abcc9 commit 6fa5a91

File tree

6 files changed

+87
-20
lines changed

6 files changed

+87
-20
lines changed

docs/rendering.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<script src="../scripts/lottie_bezier.js"></script>
44
<style>
55
.json-parent:not([hidden]) {
6-
display: flex;
6+
display: flex;
77
}
88

99
.json-parent > pre {
@@ -984,6 +984,11 @@ Translate by `p`
984984
p[0] p[1] 0 1
985985

986986

987+
<!--
988+
<script>
989+
var transform = new LottieMatrix();
990+
</script>
991+
987992
<lottie-playground example="transform.json">
988993
<form>
989994
<input title="Anchor X" type="range" min="0" value="256" max="512"/>
@@ -1064,7 +1069,6 @@ lottie.layers[2].ks.sa.k = data["Skew Angle"];
10641069
lottie.layers[2].ks.o.k = data["Opacity"];
10651070
10661071
1067-
var transform = new LottieMatrix();
10681072
transform.translate(-data["Anchor X"], -data["Anchor Y"]);
10691073
transform.scale(data["Scale X"] / 100, data["Scale Y"] / 100);
10701074
transform.skew(data["Skew"] * Math.PI / 180, data["Skew Angle"] * Math.PI / 180);
@@ -1084,6 +1088,7 @@ lottie.layers[1].shapes[0].ks.k.v = [
10841088
];
10851089
</script>
10861090
</lottie-playground>
1091+
-->
10871092

10881093
### 3D Transform
10891094

docs/scripts/simple_shader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,4 @@ class TextureFactory
440440
}
441441

442442
ShaderProgram.texture_factory = new TextureFactory();
443-
ShaderProgram.image_url = "/lottie-docs/examples/blep.png";
443+
ShaderProgram.image_url = "/lottie-docs/static/examples/blep.png";

docs/static/examples/image.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"id": "blep",
1212
"h": 512,
1313
"w": 512,
14-
"p": "/lottie-docs/static/examples/blep.png",
14+
"p": "blep.png",
1515
"u": "",
1616
"e": 0
1717
}

docs/style/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,12 @@ input[type="color"]
253253
margin: 1ex;
254254
height: 48px;
255255
}
256+
257+
.algorithm {
258+
position: relative;
259+
}
260+
261+
.algorithm select {
262+
position: absolute;
263+
right: 0;
264+
}

mkdocs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ markdown_extensions:
2626
- lottie-playground
2727
- algorithm
2828
- shape_bezier_script
29-
- effect_shader_script
3029
- lottie_specs.markdown.latex_markdown
3130
- md_extensions
3231
extra_css:

tools/md_extensions.py

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from mkdocs.structure.pages import _RelativePathTreeprocessor
1616

1717
from lottie_specs.schema import Schema
18-
from lottie_specs.markdown.lottie_markdown import LottiePlayground, LottieColor, ReferenceLink, SchemaLink
18+
from lottie_specs.markdown.lottie_markdown import LottiePlayground, LottieColor, ReferenceLink, SchemaLink, LottiePlaygroundBase
1919

2020

2121
docs_path = Path(__file__).parent.parent / "docs"
@@ -166,10 +166,63 @@ def add_json_viewer(self, builder, parent):
166166
return id
167167

168168

169-
class EffectShaderScript(LottiePlayground):
169+
class EarlyHtmlProcessor(Preprocessor):
170+
def __init__(self, tags, *a, **kw):
171+
super().__init__(*a, **kw)
172+
self.start_re = re.compile("^<(%s)" % "|".join(tags))
173+
174+
def run(self, lines):
175+
new_lines = []
176+
element_text = None
177+
end_tag = None
178+
comment = False
179+
180+
for line in lines:
181+
if comment:
182+
new_lines.append(line)
183+
if "-->" in line:
184+
comment = False
185+
elif element_text:
186+
element_text += line + "\n"
187+
if line == end_tag:
188+
self.flush(element_text, new_lines)
189+
element_text = None
190+
else:
191+
match = self.start_re.match(line)
192+
if match:
193+
self.flush(element_text, new_lines)
194+
element_text = line + "\n"
195+
end_tag = "</%s>" % match.group(1)
196+
else:
197+
new_lines.append(line)
198+
if "<!--" in line:
199+
comment = True
200+
201+
self.flush(element_text, new_lines)
202+
203+
return new_lines
204+
205+
def flush(self, element_text, new_lines):
206+
if element_text:
207+
self.on_flush(element_text, new_lines)
208+
209+
def on_flush(self, element_text, new_lines):
210+
new_lines.append(self.md.htmlStash.store(element_text))
211+
212+
213+
class EffectShaderScript(EarlyHtmlProcessor, LottiePlaygroundBase):
170214
tag_name = "effect_shader_script"
171215

172-
def populate_script(self, script_element, builder, json_data, extra_options, json_viewer_id, json_viewer_path):
216+
def __init__(self, md, schema_data):
217+
EarlyHtmlProcessor.__init__(self, [self.tag_name], md)
218+
LottiePlaygroundBase.__init__(self, schema_data)
219+
220+
def on_flush(self, element_text, new_lines):
221+
parent = etree.Element("div")
222+
self.make_element(parent, element_text)
223+
new_lines.append(self.md.htmlStash.store(parent))
224+
225+
def populate_script(self, md_element, builder, json_data, extra_options, json_viewer_id, json_viewer_path):
173226
shader_view = etree.SubElement(builder.renderer.animation_container, "canvas")
174227
shader_view.attrib["class"] = "webgl-shader"
175228
shader_view.attrib["id"] = "lottie_target_%s_canvas" % builder.anim_id
@@ -180,17 +233,18 @@ def populate_script(self, script_element, builder, json_data, extra_options, jso
180233
uniforms = {}
181234
script = ""
182235
shader_sources = []
183-
if script_element is not None:
184-
if script_element.attrib.get("type", "") == "x-shader/x-fragment":
185-
shader_source = script_element.text.strip()
186-
187-
pre = etree.SubElement(builder.element, "pre")
188-
# No glsl ;_;
189-
code = etree.SubElement(pre, "code", {"class": "language-c hljs"})
190-
code.text = AtomicString(shader_source)
191-
shader_sources.append((shader_source, int(script_element.attrib.get("passes", "1"))))
192-
else:
193-
script = script_element.text
236+
for script_element in md_element.findall("./script"):
237+
if script_element is not None:
238+
if script_element.attrib.get("type", "") == "x-shader/x-fragment":
239+
shader_source = script_element.text.strip()
240+
241+
pre = etree.SubElement(builder.element, "pre")
242+
# No glsl ;_;
243+
code = etree.SubElement(pre, "code", {"class": "language-c hljs"})
244+
code.text = AtomicString(shader_source)
245+
shader_sources.append((shader_source, int(script_element.attrib.get("passes", "1"))))
246+
else:
247+
script = script_element.text
194248

195249
if json_viewer_path:
196250
script += "this.json_viewer_contents = %s;" % json_viewer_path
@@ -679,8 +733,8 @@ def extendMarkdown(self, md):
679733
md.parser.blockprocessors.register(FunctionDocs(md.parser, expr_schema), 'function_docs', 175)
680734
md.parser.blockprocessors.register(VariableDocs(md.parser, expr_schema), 'variable_docs', 175)
681735
md.preprocessors.register(ScriptPlayground(md), 'script_playground', 29)
736+
md.preprocessors.register(EffectShaderScript(md, md.lottie_ts), "shape_bezier_script", 29)
682737
md.parser.blockprocessors.register(ShapeBezierScript(md, md.lottie_ts), "shape_bezier_script", 175)
683-
md.parser.blockprocessors.register(EffectShaderScript(md, md.lottie_ts), "effect_shader_script", 175)
684738
md.parser.blockprocessors.register(AepMatchNameTable(md.parser, md.lottie_schema), "aep_mn", 175)
685739
md.inlinePatterns.register(SectionLinkInlineProcessor(md), "sl", 175)
686740

0 commit comments

Comments
 (0)