media.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. """Media classes."""
  2. from typing import Any, Union
  3. from reflex import Component, ComponentNamespace
  4. from reflex.constants.colors import Color
  5. from reflex.vars.base import Var
  6. from .base import BaseHTML
  7. class Area(BaseHTML):
  8. """Display the area element."""
  9. tag = "area"
  10. # Alternate text for the area, used for accessibility
  11. alt: Var[Union[str, int, bool]]
  12. # Coordinates to define the shape of the area
  13. coords: Var[Union[str, int, bool]]
  14. # Specifies that the target will be downloaded when clicked
  15. download: Var[Union[str, int, bool]]
  16. # Hyperlink reference for the area
  17. href: Var[Union[str, int, bool]]
  18. # Language of the linked resource
  19. href_lang: Var[Union[str, int, bool]]
  20. # Specifies what media/device the linked resource is optimized for
  21. media: Var[Union[str, int, bool]]
  22. # A list of URLs to be notified if the user follows the hyperlink
  23. ping: Var[Union[str, int, bool]]
  24. # Specifies which referrer information to send with the link
  25. referrer_policy: Var[Union[str, int, bool]]
  26. # Specifies the relationship of the target object to the link object
  27. rel: Var[Union[str, int, bool]]
  28. # Defines the shape of the area (rectangle, circle, polygon)
  29. shape: Var[Union[str, int, bool]]
  30. # Specifies where to open the linked document
  31. target: Var[Union[str, int, bool]]
  32. class Audio(BaseHTML):
  33. """Display the audio element."""
  34. tag = "audio"
  35. # Specifies that the audio will start playing as soon as it is ready
  36. auto_play: Var[Union[str, int, bool]]
  37. # Represents the time range of the buffered media
  38. buffered: Var[Union[str, int, bool]]
  39. # Displays the standard audio controls
  40. controls: Var[Union[str, int, bool]]
  41. # Configures the CORS requests for the element
  42. cross_origin: Var[Union[str, int, bool]]
  43. # Specifies that the audio will loop
  44. loop: Var[Union[str, int, bool]]
  45. # Indicates whether the audio is muted by default
  46. muted: Var[Union[str, int, bool]]
  47. # Specifies how the audio file should be preloaded
  48. preload: Var[Union[str, int, bool]]
  49. # URL of the audio to play
  50. src: Var[Union[str, int, bool]]
  51. class Img(BaseHTML):
  52. """Display the img element."""
  53. tag = "img"
  54. # Image alignment with respect to its surrounding elements
  55. align: Var[Union[str, int, bool]]
  56. # Alternative text for the image
  57. alt: Var[Union[str, int, bool]]
  58. # Configures the CORS requests for the image
  59. cross_origin: Var[Union[str, int, bool]]
  60. # How the image should be decoded
  61. decoding: Var[Union[str, int, bool]]
  62. # Specifies an intrinsic size for the image
  63. intrinsicsize: Var[Union[str, int, bool]]
  64. # Whether the image is a server-side image map
  65. ismap: Var[Union[str, int, bool]]
  66. # Specifies the loading behavior of the image
  67. loading: Var[Union[str, int, bool]]
  68. # Referrer policy for the image
  69. referrer_policy: Var[Union[str, int, bool]]
  70. # Sizes of the image for different layouts
  71. sizes: Var[Union[str, int, bool]]
  72. # URL of the image to display
  73. src: Var[Any]
  74. # A set of source sizes and URLs for responsive images
  75. src_set: Var[Union[str, int, bool]]
  76. # The name of the map to use with the image
  77. use_map: Var[Union[str, int, bool]]
  78. @classmethod
  79. def create(cls, *children, **props) -> Component:
  80. """Override create method to apply source attribute to value if user fails to pass in attribute.
  81. Args:
  82. *children: The children of the component.
  83. **props: The props of the component.
  84. Returns:
  85. The component.
  86. """
  87. return (
  88. super().create(src=children[0], **props)
  89. if children
  90. else super().create(*children, **props)
  91. )
  92. class Map(BaseHTML):
  93. """Display the map element."""
  94. tag = "map"
  95. # Name of the map, referenced by the 'usemap' attribute in 'img' and 'object' elements
  96. name: Var[Union[str, int, bool]]
  97. class Track(BaseHTML):
  98. """Display the track element."""
  99. tag = "track"
  100. # Indicates that the track should be enabled unless the user's preferences indicate otherwise
  101. default: Var[Union[str, int, bool]]
  102. # Specifies the kind of text track
  103. kind: Var[Union[str, int, bool]]
  104. # Title of the text track, used by the browser when listing available text tracks
  105. label: Var[Union[str, int, bool]]
  106. # URL of the track file
  107. src: Var[Union[str, int, bool]]
  108. # Language of the track text data
  109. src_lang: Var[Union[str, int, bool]]
  110. class Video(BaseHTML):
  111. """Display the video element."""
  112. tag = "video"
  113. # Specifies that the video will start playing as soon as it is ready
  114. auto_play: Var[Union[str, int, bool]]
  115. # Represents the time range of the buffered media
  116. buffered: Var[Union[str, int, bool]]
  117. # Displays the standard video controls
  118. controls: Var[Union[str, int, bool]]
  119. # Configures the CORS requests for the video
  120. cross_origin: Var[Union[str, int, bool]]
  121. # Specifies that the video will loop
  122. loop: Var[Union[str, int, bool]]
  123. # Indicates whether the video is muted by default
  124. muted: Var[Union[str, int, bool]]
  125. # Indicates that the video should play 'inline', inside its element's playback area
  126. plays_inline: Var[Union[str, int, bool]]
  127. # URL of an image to show while the video is downloading, or until the user hits the play button
  128. poster: Var[Union[str, int, bool]]
  129. # Specifies how the video file should be preloaded
  130. preload: Var[Union[str, int, bool]]
  131. # URL of the video to play
  132. src: Var[Union[str, int, bool]]
  133. class Embed(BaseHTML):
  134. """Display the embed element."""
  135. tag = "embed"
  136. # URL of the embedded content
  137. src: Var[Union[str, int, bool]]
  138. # Media type of the embedded content
  139. type: Var[Union[str, int, bool]]
  140. class Iframe(BaseHTML):
  141. """Display the iframe element."""
  142. tag = "iframe"
  143. # Alignment of the iframe within the page or surrounding elements
  144. align: Var[Union[str, int, bool]]
  145. # Permissions policy for the iframe
  146. allow: Var[Union[str, int, bool]]
  147. # Content Security Policy to apply to the iframe's content
  148. csp: Var[Union[str, int, bool]]
  149. # Specifies the loading behavior of the iframe
  150. loading: Var[Union[str, int, bool]]
  151. # Name of the iframe, used as a target for hyperlinks and forms
  152. name: Var[Union[str, int, bool]]
  153. # Referrer policy for the iframe
  154. referrer_policy: Var[Union[str, int, bool]]
  155. # Security restrictions for the content in the iframe
  156. sandbox: Var[Union[str, int, bool]]
  157. # URL of the document to display in the iframe
  158. src: Var[Union[str, int, bool]]
  159. # HTML content to embed directly within the iframe
  160. src_doc: Var[Union[str, int, bool]]
  161. class Object(BaseHTML):
  162. """Display the object element."""
  163. tag = "object"
  164. # URL of the data to be used by the object
  165. data: Var[Union[str, int, bool]]
  166. # Associates the object with a form element
  167. form: Var[Union[str, int, bool]]
  168. # Name of the object, used for scripting or as a target for forms and links
  169. name: Var[Union[str, int, bool]]
  170. # Media type of the data specified in the data attribute
  171. type: Var[Union[str, int, bool]]
  172. # Name of an image map to use with the object
  173. use_map: Var[Union[str, int, bool]]
  174. class Picture(BaseHTML):
  175. """Display the picture element."""
  176. tag = "picture"
  177. class Portal(BaseHTML):
  178. """Display the portal element."""
  179. tag = "portal"
  180. class Source(BaseHTML):
  181. """Display the source element."""
  182. tag = "source"
  183. # Media query indicating what device the linked resource is optimized for
  184. media: Var[Union[str, int, bool]]
  185. # Sizes of the source for different layouts
  186. sizes: Var[Union[str, int, bool]]
  187. # URL of the media file or an image for the element to use
  188. src: Var[Union[str, int, bool]]
  189. # A set of source sizes and URLs for responsive images
  190. src_set: Var[Union[str, int, bool]]
  191. # Media type of the source
  192. type: Var[Union[str, int, bool]]
  193. class Svg(BaseHTML):
  194. """Display the svg element."""
  195. tag = "svg"
  196. # The width of the svg.
  197. width: Var[Union[str, int]]
  198. # The height of the svg.
  199. height: Var[Union[str, int]]
  200. # The XML namespace declaration.
  201. xmlns: Var[str]
  202. class Text(BaseHTML):
  203. """The SVG text component."""
  204. tag = "text"
  205. # The x coordinate of the starting point of the text baseline.
  206. x: Var[Union[str, int]]
  207. # The y coordinate of the starting point of the text baseline.
  208. y: Var[Union[str, int]]
  209. # Shifts the text position horizontally from a previous text element.
  210. dx: Var[Union[str, int]]
  211. # Shifts the text position vertically from a previous text element.
  212. dy: Var[Union[str, int]]
  213. # Rotates orientation of each individual glyph.
  214. rotate: Var[Union[str, int]]
  215. # How the text is stretched or compressed to fit the width defined by the text_length attribute.
  216. length_adjust: Var[str]
  217. # A width that the text should be scaled to fit.
  218. text_length: Var[Union[str, int]]
  219. class Line(BaseHTML):
  220. """The SVG line component."""
  221. tag = "line"
  222. # The x-axis coordinate of the line starting point.
  223. x1: Var[Union[str, int]]
  224. # The x-axis coordinate of the the line ending point.
  225. x2: Var[Union[str, int]]
  226. # The y-axis coordinate of the line starting point.
  227. y1: Var[Union[str, int]]
  228. # The y-axis coordinate of the the line ending point.
  229. y2: Var[Union[str, int]]
  230. # The total path length, in user units.
  231. path_length: Var[int]
  232. class Circle(BaseHTML):
  233. """The SVG circle component."""
  234. tag = "circle"
  235. # The x-axis coordinate of the center of the circle.
  236. cx: Var[Union[str, int]]
  237. # The y-axis coordinate of the center of the circle.
  238. cy: Var[Union[str, int]]
  239. # The radius of the circle.
  240. r: Var[Union[str, int]]
  241. # The total length for the circle's circumference, in user units.
  242. path_length: Var[int]
  243. class Ellipse(BaseHTML):
  244. """The SVG ellipse component."""
  245. tag = "ellipse"
  246. # The x position of the center of the ellipse.
  247. cx: Var[Union[str, int]]
  248. # The y position of the center of the ellipse.
  249. cy: Var[Union[str, int]]
  250. # The radius of the ellipse on the x axis.
  251. rx: Var[Union[str, int]]
  252. # The radius of the ellipse on the y axis.
  253. ry: Var[Union[str, int]]
  254. # The total length for the ellipse's circumference, in user units.
  255. path_length: Var[int]
  256. class Rect(BaseHTML):
  257. """The SVG rect component."""
  258. tag = "rect"
  259. # The x coordinate of the rect.
  260. x: Var[Union[str, int]]
  261. # The y coordinate of the rect.
  262. y: Var[Union[str, int]]
  263. # The width of the rect
  264. width: Var[Union[str, int]]
  265. # The height of the rect.
  266. height: Var[Union[str, int]]
  267. # The horizontal corner radius of the rect. Defaults to ry if it is specified.
  268. rx: Var[Union[str, int]]
  269. # The vertical corner radius of the rect. Defaults to rx if it is specified.
  270. ry: Var[Union[str, int]]
  271. # The total length of the rectangle's perimeter, in user units.
  272. path_length: Var[int]
  273. class Polygon(BaseHTML):
  274. """The SVG polygon component."""
  275. tag = "polygon"
  276. # defines the list of points (pairs of x,y absolute coordinates) required to draw the polygon.
  277. points: Var[str]
  278. # This prop lets specify the total length for the path, in user units.
  279. path_length: Var[int]
  280. class Defs(BaseHTML):
  281. """Display the defs element."""
  282. tag = "defs"
  283. class LinearGradient(BaseHTML):
  284. """Display the linearGradient element."""
  285. tag = "linearGradient"
  286. # Units for the gradient.
  287. gradient_units: Var[Union[str, bool]]
  288. # Transform applied to the gradient.
  289. gradient_transform: Var[Union[str, bool]]
  290. # Method used to spread the gradient.
  291. spread_method: Var[Union[str, bool]]
  292. # X coordinate of the starting point of the gradient.
  293. x1: Var[Union[str, int, bool]]
  294. # X coordinate of the ending point of the gradient.
  295. x2: Var[Union[str, int, bool]]
  296. # Y coordinate of the starting point of the gradient.
  297. y1: Var[Union[str, int, bool]]
  298. # Y coordinate of the ending point of the gradient.
  299. y2: Var[Union[str, int, bool]]
  300. class RadialGradient(BaseHTML):
  301. """Display the radialGradient element."""
  302. tag = "radialGradient"
  303. # The x coordinate of the end circle of the radial gradient.
  304. cx: Var[Union[str, int, bool]]
  305. # The y coordinate of the end circle of the radial gradient.
  306. cy: Var[Union[str, int, bool]]
  307. # The radius of the start circle of the radial gradient.
  308. fr: Var[Union[str, int, bool]]
  309. # The x coordinate of the start circle of the radial gradient.
  310. fx: Var[Union[str, int, bool]]
  311. # The y coordinate of the start circle of the radial gradient.
  312. fy: Var[Union[str, int, bool]]
  313. # Units for the gradient.
  314. gradient_units: Var[Union[str, bool]]
  315. # Transform applied to the gradient.
  316. gradient_transform: Var[Union[str, bool]]
  317. # The radius of the end circle of the radial gradient.
  318. r: Var[Union[str, int, bool]]
  319. # Method used to spread the gradient.
  320. spread_method: Var[Union[str, bool]]
  321. class Stop(BaseHTML):
  322. """Display the stop element."""
  323. tag = "stop"
  324. # Offset of the gradient stop.
  325. offset: Var[Union[str, float, int]]
  326. # Color of the gradient stop.
  327. stop_color: Var[Union[str, Color, bool]]
  328. # Opacity of the gradient stop.
  329. stop_opacity: Var[Union[str, float, int, bool]]
  330. class Path(BaseHTML):
  331. """Display the path element."""
  332. tag = "path"
  333. # Defines the shape of the path.
  334. d: Var[Union[str, int, bool]]
  335. class SVG(ComponentNamespace):
  336. """SVG component namespace."""
  337. text = staticmethod(Text.create)
  338. line = staticmethod(Line.create)
  339. circle = staticmethod(Circle.create)
  340. ellipse = staticmethod(Ellipse.create)
  341. rect = staticmethod(Rect.create)
  342. polygon = staticmethod(Polygon.create)
  343. path = staticmethod(Path.create)
  344. stop = staticmethod(Stop.create)
  345. linear_gradient = staticmethod(LinearGradient.create)
  346. radial_gradient = staticmethod(RadialGradient.create)
  347. defs = staticmethod(Defs.create)
  348. __call__ = staticmethod(Svg.create)
  349. area = Area.create
  350. audio = Audio.create
  351. image = img = Img.create
  352. map = Map.create
  353. track = Track.create
  354. video = Video.create
  355. embed = Embed.create
  356. iframe = Iframe.create
  357. object = Object.create
  358. picture = Picture.create
  359. portal = Portal.create
  360. source = Source.create
  361. svg = SVG()