@@ -8,43 +8,63 @@ class PhotoCompare {
88
99 PhotoCompare (this .wf);
1010
11- BuildOp get buildOp => BuildOp (
11+ BuildOp get buildOp => BuildOp . v1 (
1212 defaultStyles: (_) => {'margin' : '0.5em 0' },
13- onChild: (childMeta) {
14- if (childMeta.element.localName == 'img' ) {
15- childMeta['display' ] = 'block' ;
13+ onChild: (tree, subTree) {
14+ if (subTree.element.localName == 'img' ) {
15+ subTree.register (
16+ BuildOp .v1 (
17+ onRenderBlock: (_, placeholder) {
18+ final child = placeholder.firstChild;
19+ if (child != null ) {
20+ final value = tree.value <_Images >();
21+ if (value == null ) {
22+ tree.value (_Images ([child]));
23+ } else {
24+ value.widgets.add (child);
25+ }
26+ }
27+ return placeholder;
28+ },
29+ priority: 5000000000000000 , // Priority._baseBoxModel
30+ ),
31+ );
1632 }
1733 },
18- onWidgets: (meta, widgets) {
19- final images = < Widget > [];
20- for (final widget in widgets) {
21- if (widget is WidgetPlaceholder <ImageMetadata >) {
22- images.add (widget);
23- }
24- }
34+ onParsed: (tree) {
35+ final replacement = tree.parent.sub ();
36+ final images = tree.value <_Images >()? .widgets;
37+ if (images == null || images.length != 2 ) return tree;
2538
26- if (images.length != 2 ) return widgets;
27-
28- final a = meta.element.attributes;
39+ final a = tree.element.attributes;
2940 final configJson = a['data-config' ] ?? '' ;
30- if (configJson.isEmpty) return widgets ;
41+ if (configJson.isEmpty) return tree ;
3142
3243 final Map config = json.decode (configJson);
3344 final width = (config['width' ] as num ? )? .toDouble ();
3445 final height = (config['height' ] as num ? )? .toDouble ();
35- if (width == null || height == null ) return widgets;
36-
37- return [
38- _PhotoCompareWidget (
39- aspectRatio: width / height,
40- image0: images[0 ],
41- image1: images[1 ],
42- ),
43- ];
46+ if (width == null || height == null ) return tree;
47+
48+ return replacement
49+ ..append (
50+ WidgetBit .block (
51+ tree.parent,
52+ _PhotoCompareWidget (
53+ aspectRatio: width / height,
54+ image0: images[0 ],
55+ image1: images[1 ],
56+ ),
57+ ),
58+ );
4459 },
4560 );
4661}
4762
63+ class _Images {
64+ final List <Widget > widgets;
65+ const _Images (this .widgets);
66+ }
67+
4868class _PhotoCompareWidget extends StatefulWidget {
4969 final double aspectRatio;
5070 final Widget image0;
0 commit comments