blitz-pdf 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +6 -6
  2. package/THIRD_PARTY_NOTICES.md +5 -2
  3. package/docs/layout-regressions.md +65 -0
  4. package/docs/pagination-regressions.md +7 -6
  5. package/package.json +1 -1
  6. package/vendor/README.md +35 -0
  7. package/vendor/blitz-dom/Cargo.toml +113 -0
  8. package/vendor/blitz-dom/LICENSE-APACHE +176 -0
  9. package/vendor/blitz-dom/LICENSE-MIT +23 -0
  10. package/vendor/blitz-dom/assets/default.css +1142 -0
  11. package/vendor/blitz-dom/assets/moz-bullet-font.otf +0 -0
  12. package/vendor/blitz-dom/src/accessibility.rs +255 -0
  13. package/vendor/blitz-dom/src/config.rs +97 -0
  14. package/vendor/blitz-dom/src/cssom.rs +971 -0
  15. package/vendor/blitz-dom/src/debug.rs +206 -0
  16. package/vendor/blitz-dom/src/document.rs +3395 -0
  17. package/vendor/blitz-dom/src/events/driver.rs +427 -0
  18. package/vendor/blitz-dom/src/events/focus.rs +40 -0
  19. package/vendor/blitz-dom/src/events/ime.rs +31 -0
  20. package/vendor/blitz-dom/src/events/keyboard.rs +174 -0
  21. package/vendor/blitz-dom/src/events/mod.rs +315 -0
  22. package/vendor/blitz-dom/src/events/pointer.rs +849 -0
  23. package/vendor/blitz-dom/src/font_metrics.rs +177 -0
  24. package/vendor/blitz-dom/src/form.rs +463 -0
  25. package/vendor/blitz-dom/src/html.rs +38 -0
  26. package/vendor/blitz-dom/src/iframe.rs +186 -0
  27. package/vendor/blitz-dom/src/layout/construct.rs +1328 -0
  28. package/vendor/blitz-dom/src/layout/damage.rs +642 -0
  29. package/vendor/blitz-dom/src/layout/inline.rs +1160 -0
  30. package/vendor/blitz-dom/src/layout/list.rs +237 -0
  31. package/vendor/blitz-dom/src/layout/mod.rs +969 -0
  32. package/vendor/blitz-dom/src/layout/paint_tree.rs +462 -0
  33. package/vendor/blitz-dom/src/layout/replaced.rs +439 -0
  34. package/vendor/blitz-dom/src/layout/table.rs +967 -0
  35. package/vendor/blitz-dom/src/layout/text_transform.rs +979 -0
  36. package/vendor/blitz-dom/src/layout/writing_mode.rs +437 -0
  37. package/vendor/blitz-dom/src/lib.rs +160 -0
  38. package/vendor/blitz-dom/src/mutator.rs +1818 -0
  39. package/vendor/blitz-dom/src/net.rs +649 -0
  40. package/vendor/blitz-dom/src/node/attributes.rs +60 -0
  41. package/vendor/blitz-dom/src/node/custom_widget.rs +178 -0
  42. package/vendor/blitz-dom/src/node/element.rs +1106 -0
  43. package/vendor/blitz-dom/src/node/mod.rs +30 -0
  44. package/vendor/blitz-dom/src/node/node.rs +2036 -0
  45. package/vendor/blitz-dom/src/node/scrollbar.rs +237 -0
  46. package/vendor/blitz-dom/src/node/serialize.rs +225 -0
  47. package/vendor/blitz-dom/src/node/stylo_data.rs +142 -0
  48. package/vendor/blitz-dom/src/node/svg.rs +265 -0
  49. package/vendor/blitz-dom/src/node/text.rs +804 -0
  50. package/vendor/blitz-dom/src/query_selector.rs +275 -0
  51. package/vendor/blitz-dom/src/resolve.rs +474 -0
  52. package/vendor/blitz-dom/src/resolved_style.rs +797 -0
  53. package/vendor/blitz-dom/src/scrolling.rs +780 -0
  54. package/vendor/blitz-dom/src/selection.rs +122 -0
  55. package/vendor/blitz-dom/src/stylo.rs +1518 -0
  56. package/vendor/blitz-dom/src/stylo_device.rs +88 -0
  57. package/vendor/blitz-dom/src/stylo_to_cursor_icon.rs +49 -0
  58. package/vendor/blitz-dom/src/stylo_to_kurbo.rs +129 -0
  59. package/vendor/blitz-dom/src/stylo_to_parley.rs +655 -0
  60. package/vendor/blitz-dom/src/traversal.rs +600 -0
  61. package/vendor/blitz-dom/src/tree.rs +136 -0
  62. package/vendor/blitz-dom/src/url.rs +63 -0
  63. package/vendor/blitz-dom/src/util.rs +256 -0
  64. package/wasm/blitz_pdf_bg.wasm +0 -0
@@ -0,0 +1,60 @@
1
+ use std::ops::{Deref, DerefMut};
2
+
3
+ use markup5ever::QualName;
4
+ use thin_vec::ThinVec;
5
+
6
+ /// A tag attribute, e.g. `class="test"` in `<div class="test" ...>`.
7
+ #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
8
+ pub struct Attribute {
9
+ /// The name of the attribute (e.g. the `class` in `<div class="test">`)
10
+ pub name: QualName,
11
+ /// The value of the attribute (e.g. the `"test"` in `<div class="test">`)
12
+ pub value: String,
13
+ }
14
+
15
+ #[derive(Clone, Debug)]
16
+ pub struct Attributes {
17
+ inner: ThinVec<Attribute>,
18
+ }
19
+
20
+ impl Attributes {
21
+ pub fn new(inner: Vec<Attribute>) -> Self {
22
+ Self {
23
+ inner: inner.into_iter().collect(),
24
+ }
25
+ }
26
+
27
+ pub fn get(&mut self, name: &QualName) -> Option<&Attribute> {
28
+ self.inner.iter().find(|attr| attr.name == *name)
29
+ }
30
+
31
+ pub fn set(&mut self, name: QualName, value: &str) {
32
+ let existing_attr = self.inner.iter_mut().find(|a| a.name == name);
33
+ if let Some(existing_attr) = existing_attr {
34
+ existing_attr.value.clear();
35
+ existing_attr.value.push_str(value);
36
+ } else {
37
+ self.push(Attribute {
38
+ name: name.clone(),
39
+ value: value.to_string(),
40
+ });
41
+ }
42
+ }
43
+
44
+ pub fn remove(&mut self, name: &QualName) -> Option<Attribute> {
45
+ let idx = self.inner.iter().position(|attr| attr.name == *name);
46
+ idx.map(|idx| self.inner.remove(idx))
47
+ }
48
+ }
49
+
50
+ impl Deref for Attributes {
51
+ type Target = ThinVec<Attribute>;
52
+ fn deref(&self) -> &Self::Target {
53
+ &self.inner
54
+ }
55
+ }
56
+ impl DerefMut for Attributes {
57
+ fn deref_mut(&mut self) -> &mut Self::Target {
58
+ &mut self.inner
59
+ }
60
+ }
@@ -0,0 +1,178 @@
1
+ use std::any::Any;
2
+
3
+ use anyrender::ResourceId;
4
+ use blitz_traits::events::UiEvent;
5
+ pub use style::properties::ComputedValues as ComputedStyles;
6
+ // use accesskit::Node as AccessKitNode;
7
+ // use taffy::{LayoutInput, LayoutOutput};
8
+
9
+ pub use anyrender::{RenderContext, Scene};
10
+
11
+ use crate::BaseDocument;
12
+ use crate::layout::replaced::IntrinsicSizes;
13
+
14
+ impl BaseDocument {
15
+ pub fn can_create_surfaces(&mut self, render_context: &mut dyn RenderContext) {
16
+ for &node_id in self.custom_widget_nodes.iter() {
17
+ let node = &mut self.nodes[node_id];
18
+ if let Some(widget_data) = node
19
+ .element_data_mut()
20
+ .and_then(|el| el.custom_widget_data_mut())
21
+ {
22
+ let mut render_context = ProxyRenderContext {
23
+ resource_ids: &mut widget_data.active_resource_ids,
24
+ inner: render_context,
25
+ };
26
+
27
+ widget_data
28
+ .widget
29
+ .can_create_surfaces(&mut render_context as _);
30
+ }
31
+ }
32
+ }
33
+
34
+ pub fn destroy_surfaces(&mut self) {
35
+ for &node_id in self.custom_widget_nodes.iter() {
36
+ let node = &mut self.nodes[node_id];
37
+ if let Some(widget_data) = node
38
+ .element_data_mut()
39
+ .and_then(|el| el.custom_widget_data_mut())
40
+ {
41
+ widget_data.widget.destroy_surfaces();
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ /// A `RenderContext` that proxies resource registrations through to an inner `RenderContext`
48
+ /// and also keeps track of the `ResourceId`s of all sucessfully registered resources so that
49
+ /// they can be automatically unregistered if the Widget's node is dropped.
50
+ pub struct ProxyRenderContext<'widget, 'rend> {
51
+ pub resource_ids: &'widget mut Vec<ResourceId>,
52
+ pub inner: &'rend mut dyn RenderContext,
53
+ }
54
+
55
+ impl anyrender::RenderContext for ProxyRenderContext<'_, '_> {
56
+ fn try_register_custom_resource(
57
+ &mut self,
58
+ resource: Box<dyn Any>,
59
+ ) -> Result<ResourceId, anyrender::RegisterResourceError> {
60
+ let id = self.inner.try_register_custom_resource(resource)?;
61
+ self.resource_ids.push(id);
62
+ Ok(id)
63
+ }
64
+
65
+ fn unregister_resource(&mut self, resource_id: ResourceId) {
66
+ self.resource_ids.retain(|id| *id != resource_id);
67
+ self.inner.unregister_resource(resource_id);
68
+ }
69
+
70
+ fn renderer_specific_context(&self) -> Option<Box<dyn std::any::Any>> {
71
+ self.inner.renderer_specific_context()
72
+ }
73
+ }
74
+
75
+ pub trait Widget {
76
+ // DOM lifecycle
77
+
78
+ /// The widget was attached to the DOM
79
+ fn connected(&mut self) {}
80
+ /// The widget was removed from the DOM
81
+ fn disconnected(&mut self) {}
82
+ /// One of the widget's attributes changed
83
+ fn attribute_changed(&mut self, name: &str, old_value: Option<&str>, new_value: Option<&str>) {
84
+ let _ = (name, old_value, new_value);
85
+ }
86
+
87
+ // Renderer lifecycle
88
+
89
+ /// The renderer is active
90
+ ///
91
+ /// `ctx` parameter can be downcast to get access to renderer-specific contexts (e.g. the WGPU Device and Queue)
92
+ fn can_create_surfaces(&mut self, render_ctx: &mut dyn RenderContext) {
93
+ let _ = render_ctx;
94
+ }
95
+ /// The renderer is no longer active (destroy textures here)
96
+ fn destroy_surfaces(&mut self) {}
97
+
98
+ // Other
99
+
100
+ /// Whether the widget currently requires redraws (e.g. because it is animating).
101
+ ///
102
+ /// Returning `true` causes the document to continuously schedule redraws
103
+ /// (and hence repaints of the widget). Static widgets should return `false`.
104
+ fn requires_redraw(&self) -> bool {
105
+ false
106
+ }
107
+
108
+ /// Handle input events (mouse, keyboard, etc)
109
+ fn handle_event(&mut self, event: &UiEvent) {
110
+ let _ = event;
111
+ }
112
+
113
+ /// The widget's intrinsic dimensions: an intrinsic width, height and
114
+ /// aspect ratio, each of which may independently be absent.
115
+ ///
116
+ /// An absent dimension is sized as it would be without the widget (for a
117
+ /// replaced element, the element's own intrinsic dimension or the default
118
+ /// object size).
119
+ fn intrinsic_sizes(&self) -> IntrinsicSizes {
120
+ IntrinsicSizes::default()
121
+ }
122
+
123
+ /// Callback for the widget to paint it's content.
124
+ ///
125
+ /// Output is recorded to an AnyRender `Scene`.
126
+ /// If the widget wants to render to a WGPU texture or similar then it should:
127
+ /// - Get a handle to the Device and Queue in `can_create_surfaces`
128
+ /// - Create it's own texture
129
+ /// - Pass the `ResourceId` of the paint for an Image in the AnyRender `Scene`
130
+ fn paint(
131
+ &mut self,
132
+ render_ctx: &mut dyn RenderContext,
133
+ styles: &ComputedStyles,
134
+ width: u32,
135
+ height: u32,
136
+ scale: f64,
137
+ ) -> Scene {
138
+ let _ = (render_ctx, styles, width, height, scale);
139
+ Scene::new()
140
+ }
141
+
142
+ // TODO: allow for multiple nodes per widget
143
+ // fn accessibility_tree(&mut self) -> AccessKitNode;
144
+
145
+ // TODO: simpler layout mode?
146
+ // fn layout(&mut self, inputs: LayoutInput, styles: &ComputedStyles) -> LayoutOutput;
147
+ }
148
+
149
+ #[derive(Debug, Copy, Clone, Eq, PartialEq)]
150
+ pub enum CustomWidgetStatus {
151
+ Suspended,
152
+ Active,
153
+ PendingRemoval,
154
+ }
155
+
156
+ pub struct CustomWidgetData {
157
+ /// The custom widget
158
+ pub widget: Box<dyn Widget>,
159
+ /// The custom widget's status
160
+ pub status: CustomWidgetStatus,
161
+ /// The IDs of active resources
162
+ /// (stored so that we can automatically unregister them if/when the widget is destroyed).
163
+ pub active_resource_ids: Vec<ResourceId>,
164
+ }
165
+
166
+ impl CustomWidgetData {
167
+ pub(crate) fn new(widget: Box<dyn Widget>) -> Self {
168
+ Self {
169
+ widget,
170
+ status: CustomWidgetStatus::Suspended,
171
+ active_resource_ids: Vec::new(),
172
+ }
173
+ }
174
+
175
+ pub(crate) fn take_resource_ids(&mut self) -> Vec<ResourceId> {
176
+ core::mem::take(&mut self.active_resource_ids)
177
+ }
178
+ }