palestine 0.1.0__tar.gz

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 (80) hide show
  1. palestine-0.1.0/.gitignore +30 -0
  2. palestine-0.1.0/PKG-INFO +140 -0
  3. palestine-0.1.0/README.md +119 -0
  4. palestine-0.1.0/palestine/__init__.py +120 -0
  5. palestine-0.1.0/palestine/analytics.py +144 -0
  6. palestine-0.1.0/palestine/animate.py +194 -0
  7. palestine-0.1.0/palestine/assertions.py +203 -0
  8. palestine-0.1.0/palestine/auth.py +185 -0
  9. palestine-0.1.0/palestine/benchmark.py +147 -0
  10. palestine-0.1.0/palestine/cache.py +208 -0
  11. palestine-0.1.0/palestine/chart.py +339 -0
  12. palestine-0.1.0/palestine/component.py +99 -0
  13. palestine-0.1.0/palestine/constants.py +46 -0
  14. palestine-0.1.0/palestine/debug.py +166 -0
  15. palestine-0.1.0/palestine/diff.py +184 -0
  16. palestine-0.1.0/palestine/elements.py +408 -0
  17. palestine-0.1.0/palestine/email.py +156 -0
  18. palestine-0.1.0/palestine/events.py +98 -0
  19. palestine-0.1.0/palestine/export.py +101 -0
  20. palestine-0.1.0/palestine/feed.py +212 -0
  21. palestine-0.1.0/palestine/forms.py +436 -0
  22. palestine-0.1.0/palestine/graphql.py +183 -0
  23. palestine-0.1.0/palestine/i18n.py +236 -0
  24. palestine-0.1.0/palestine/markdown.py +301 -0
  25. palestine-0.1.0/palestine/middleware.py +160 -0
  26. palestine-0.1.0/palestine/mock.py +137 -0
  27. palestine-0.1.0/palestine/nodes.py +568 -0
  28. palestine-0.1.0/palestine/og.py +217 -0
  29. palestine-0.1.0/palestine/orm.py +231 -0
  30. palestine-0.1.0/palestine/parse.py +84 -0
  31. palestine-0.1.0/palestine/pdf.py +110 -0
  32. palestine-0.1.0/palestine/pretty.py +131 -0
  33. palestine-0.1.0/palestine/pwa.py +186 -0
  34. palestine-0.1.0/palestine/reactive.py +255 -0
  35. palestine-0.1.0/palestine/render.py +142 -0
  36. palestine-0.1.0/palestine/route.py +249 -0
  37. palestine-0.1.0/palestine/security.py +215 -0
  38. palestine-0.1.0/palestine/seo.py +175 -0
  39. palestine-0.1.0/palestine/serialize.py +167 -0
  40. palestine-0.1.0/palestine/sitemap.py +115 -0
  41. palestine-0.1.0/palestine/store.py +202 -0
  42. palestine-0.1.0/palestine/structured.py +206 -0
  43. palestine-0.1.0/palestine/styled.py +290 -0
  44. palestine-0.1.0/palestine/table.py +278 -0
  45. palestine-0.1.0/palestine/template.py +208 -0
  46. palestine-0.1.0/palestine/test_utils.py +188 -0
  47. palestine-0.1.0/palestine/tests/__init__.py +1 -0
  48. palestine-0.1.0/palestine/tests/conftest.py +133 -0
  49. palestine-0.1.0/palestine/tests/test_assertions.py +146 -0
  50. palestine-0.1.0/palestine/tests/test_auth.py +119 -0
  51. palestine-0.1.0/palestine/tests/test_cache.py +142 -0
  52. palestine-0.1.0/palestine/tests/test_chart.py +129 -0
  53. palestine-0.1.0/palestine/tests/test_complete.py +595 -0
  54. palestine-0.1.0/palestine/tests/test_component.py +128 -0
  55. palestine-0.1.0/palestine/tests/test_diff.py +135 -0
  56. palestine-0.1.0/palestine/tests/test_events.py +189 -0
  57. palestine-0.1.0/palestine/tests/test_forms.py +106 -0
  58. palestine-0.1.0/palestine/tests/test_fuzz.py +345 -0
  59. palestine-0.1.0/palestine/tests/test_integration.py +358 -0
  60. palestine-0.1.0/palestine/tests/test_new_features.py +414 -0
  61. palestine-0.1.0/palestine/tests/test_nodes.py +427 -0
  62. palestine-0.1.0/palestine/tests/test_pretty.py +68 -0
  63. palestine-0.1.0/palestine/tests/test_reactive.py +201 -0
  64. palestine-0.1.0/palestine/tests/test_regression.py +270 -0
  65. palestine-0.1.0/palestine/tests/test_render.py +192 -0
  66. palestine-0.1.0/palestine/tests/test_route.py +97 -0
  67. palestine-0.1.0/palestine/tests/test_security.py +177 -0
  68. palestine-0.1.0/palestine/tests/test_serialize.py +194 -0
  69. palestine-0.1.0/palestine/tests/test_table.py +127 -0
  70. palestine-0.1.0/palestine/tests/test_template.py +132 -0
  71. palestine-0.1.0/palestine/tests/test_validate.py +276 -0
  72. palestine-0.1.0/palestine/tests/test_wsgi.py +114 -0
  73. palestine-0.1.0/palestine/types.py +207 -0
  74. palestine-0.1.0/palestine/upload.py +169 -0
  75. palestine-0.1.0/palestine/validate.py +313 -0
  76. palestine-0.1.0/palestine/vdom.py +272 -0
  77. palestine-0.1.0/palestine/webcomponent.py +161 -0
  78. palestine-0.1.0/palestine/websocket.py +204 -0
  79. palestine-0.1.0/palestine/wsgi.py +140 -0
  80. palestine-0.1.0/pyproject.toml +39 -0
@@ -0,0 +1,30 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+ .Python
6
+ build/
7
+ develop-eggs/
8
+ dist/
9
+ downloads/
10
+ eggs/
11
+ .eggs/
12
+ lib/
13
+ lib64/
14
+ parts/
15
+ sdist/
16
+ var/
17
+ wheels/
18
+ *.egg-info/
19
+ .installed.cfg
20
+ *.egg
21
+ .pytest_cache/
22
+ .coverage
23
+ htmlcov/
24
+ .tox/
25
+ .venv
26
+ venv/
27
+ ENV/
28
+ env/
29
+ .commandcode/
30
+ docs/
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.5
2
+ Name: palestine
3
+ Version: 0.1.0
4
+ Summary: A full spec DOM implementation in Python
5
+ Project-URL: Homepage, https://github.com/u84u/palestine
6
+ Project-URL: Documentation, https://github.com/u84u/palestine#readme
7
+ Project-URL: Repository, https://github.com/u84u/palestine
8
+ Project-URL: Issues, https://github.com/u84u/palestine/issues
9
+ Author: u84u
10
+ License: MIT
11
+ Keywords: components,dom,framework,html,template,web
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Topic :: Internet :: WWW/HTTP
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.14
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Palestine
23
+
24
+ A full spec DOM implementation in Python.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install palestine
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ```python
35
+ from palestine import Document, Button, Div, Span
36
+
37
+ doc = Document()
38
+ body = doc.create_element('body')
39
+ doc.append_child(body)
40
+
41
+ btn = Button(type="submit", class_="primary")
42
+ btn.append_child(Text("Click me"))
43
+ body.append_child(btn)
44
+
45
+ print(doc)
46
+ # <!DOCTYPE html>
47
+ # <html><body><button type="submit" class="primary">Click me</button></body></html>
48
+ ```
49
+
50
+ ## Features
51
+
52
+ ### Core DOM
53
+
54
+ - **Nodes & Elements** - Full DOM tree implementation with `Node`, `Element`, `Text`, `Comment`, and `Document`
55
+ - **HTML Parsing** - Parse HTML strings into DOM trees with `parse_html` and `parse_fragment`
56
+ - **Rendering** - Render elements to HTML with `render_element`, `render_node`, and `minify`
57
+
58
+ ### Components & Templating
59
+
60
+ - **Template Engine** - Create reusable templates with `Template`
61
+ - **Component System** - Build composable UI components with `Component`, `@component`, and `register_component`
62
+ - **Virtual DOM** - Efficient updates with `VNode`, `h`, `render_vdom`, `diff_vdom`, and `patch`
63
+ - **Diffing** - Compute and apply patches between DOM trees with `diff` and `apply_patches`
64
+
65
+ ### Routing & State
66
+
67
+ - **Router** - Client-side routing with `Router`, `Route`, and `link_element`
68
+ - **Reactive Signals** - Fine-grained reactivity with `Signal`, `Computed`, `Effect`, `computed`, `effect`, `batch`
69
+ - **Store** - Application state management with `Store`, `Action`, `create_store`, `combine_reducers`
70
+
71
+ ### Styling & Animation
72
+
73
+ - **Styled Elements** - CSS-in-Python with `Styles`, `styled`, `Box`, `Flex`, `Grid`
74
+ - **Animations** - Keyframe animations and transitions with `Animation`, `Transition`, `animate`
75
+ - **Built-in Animations** - Pre-built effects like `fade_in`, `fade_out`, `slide_in`, `scale_in`
76
+
77
+ ### Forms & Validation
78
+
79
+ - **Form Builder** - Declarative form construction with `FormBuilder`
80
+ - **Validation** - Schema validation with `Validator`, `Required`, `Email`, `URL`, `Pattern`, and more
81
+ - **Serialization** - JSON and form data serialization with `to_json`, `form_data`, `to_query_string`
82
+
83
+ ### Web Standards
84
+
85
+ - **Internationalization** - i18n support with `I18n`, `create_i18n`
86
+ - **SEO** - Generate sitemaps, robots.txt, and structured data with `SEO`
87
+ - **PWA** - Service worker generation with `PWA`, `generate_service_worker`
88
+ - **Feeds** - RSS and Atom feed generation with `RSSFeed`, `AtomFeed`
89
+ - **Sitemaps** - XML sitemap generation with `Sitemap`, `SitemapIndex`
90
+ - **Structured Data** - Schema.org markup with `Schema`
91
+ - **Open Graph & Twitter Cards** - Social meta tags with `OpenGraph`, `TwitterCard`
92
+
93
+ ### Security
94
+
95
+ - **CSRF Protection** - Token generation and validation
96
+ - **HTML Sanitization** - Safe HTML rendering with `sanitize_html`, `escape_html`
97
+ - **Password Hashing** - Secure password storage with `hash_password`, `verify_password`
98
+ - **Rate Limiting** - Request throttling with `RateLimiter`
99
+ - **CSP Headers** - Content Security Policy generation
100
+
101
+ ### Advanced Features
102
+
103
+ - **Web Components** - Custom elements with shadow DOM via `CustomElement`, `define_element`
104
+ - **WebSocket** - Real-time communication with `WebSocket`, `Channel`
105
+ - **ORM** - Database models with `Model`, `Field`, `QuerySet`
106
+ - **Authentication** - User auth with `Auth`, `login_user`, `logout_user`, `@login_required`
107
+ - **File Uploads** - Handle file uploads with `FileUpload`, `UploadedFile`
108
+ - **Caching** - LRU cache and memoization with `Cache`, `memoize`, `LRUCache`
109
+ - **Charts** - Data visualization with `Chart`, `BarChart`, `LineChart`, `PieChart`
110
+ - **PDF Generation** - Convert HTML to PDF with `PDF`, `html_to_pdf`
111
+ - **Email** - Email composition with `Email`, `EmailTemplate`
112
+ - **GraphQL** - GraphQL client with `GraphQLClient`, `query`, `mutation`
113
+ - **Middleware** - Request/response middleware with `MiddlewareStack`
114
+
115
+ ### Developer Tools
116
+
117
+ - **Testing** - Test utilities with `TestCase`, `TestClient`, `TestResponse`
118
+ - **Assertions** - DOM assertions with `ElementAssert`, `DocumentAssert`
119
+ - **Mock Server** - API mocking with `MockServer`, `MockResponse`
120
+ - **Debugging** - Debug tools with `inspect`, `tree`, `stats`, `validate_html`
121
+ - **Benchmarks** - Performance testing with `Benchmark`, `benchmark_render`
122
+ - **Pretty Print** - Formatted HTML output with `pretty_print`
123
+ - **Markdown** - Markdown parsing with `markdown_to_html`, `Markdown`
124
+ - **Export** - Data export to CSV, TSV, JSON, XML, Excel with `to_csv`, `to_excel`
125
+ - **Analytics** - Analytics integration with `GoogleAnalytics`, `PlausibleAnalytics`
126
+
127
+ ## WSGI Integration
128
+
129
+ ```python
130
+ from palestine import Document, html_response
131
+
132
+ def app(environ, start_response):
133
+ doc = Document()
134
+ # ... build your page
135
+ return html_response(doc, start_response)
136
+ ```
137
+
138
+ ## License
139
+
140
+ MIT
@@ -0,0 +1,119 @@
1
+ # Palestine
2
+
3
+ A full spec DOM implementation in Python.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install palestine
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ from palestine import Document, Button, Div, Span
15
+
16
+ doc = Document()
17
+ body = doc.create_element('body')
18
+ doc.append_child(body)
19
+
20
+ btn = Button(type="submit", class_="primary")
21
+ btn.append_child(Text("Click me"))
22
+ body.append_child(btn)
23
+
24
+ print(doc)
25
+ # <!DOCTYPE html>
26
+ # <html><body><button type="submit" class="primary">Click me</button></body></html>
27
+ ```
28
+
29
+ ## Features
30
+
31
+ ### Core DOM
32
+
33
+ - **Nodes & Elements** - Full DOM tree implementation with `Node`, `Element`, `Text`, `Comment`, and `Document`
34
+ - **HTML Parsing** - Parse HTML strings into DOM trees with `parse_html` and `parse_fragment`
35
+ - **Rendering** - Render elements to HTML with `render_element`, `render_node`, and `minify`
36
+
37
+ ### Components & Templating
38
+
39
+ - **Template Engine** - Create reusable templates with `Template`
40
+ - **Component System** - Build composable UI components with `Component`, `@component`, and `register_component`
41
+ - **Virtual DOM** - Efficient updates with `VNode`, `h`, `render_vdom`, `diff_vdom`, and `patch`
42
+ - **Diffing** - Compute and apply patches between DOM trees with `diff` and `apply_patches`
43
+
44
+ ### Routing & State
45
+
46
+ - **Router** - Client-side routing with `Router`, `Route`, and `link_element`
47
+ - **Reactive Signals** - Fine-grained reactivity with `Signal`, `Computed`, `Effect`, `computed`, `effect`, `batch`
48
+ - **Store** - Application state management with `Store`, `Action`, `create_store`, `combine_reducers`
49
+
50
+ ### Styling & Animation
51
+
52
+ - **Styled Elements** - CSS-in-Python with `Styles`, `styled`, `Box`, `Flex`, `Grid`
53
+ - **Animations** - Keyframe animations and transitions with `Animation`, `Transition`, `animate`
54
+ - **Built-in Animations** - Pre-built effects like `fade_in`, `fade_out`, `slide_in`, `scale_in`
55
+
56
+ ### Forms & Validation
57
+
58
+ - **Form Builder** - Declarative form construction with `FormBuilder`
59
+ - **Validation** - Schema validation with `Validator`, `Required`, `Email`, `URL`, `Pattern`, and more
60
+ - **Serialization** - JSON and form data serialization with `to_json`, `form_data`, `to_query_string`
61
+
62
+ ### Web Standards
63
+
64
+ - **Internationalization** - i18n support with `I18n`, `create_i18n`
65
+ - **SEO** - Generate sitemaps, robots.txt, and structured data with `SEO`
66
+ - **PWA** - Service worker generation with `PWA`, `generate_service_worker`
67
+ - **Feeds** - RSS and Atom feed generation with `RSSFeed`, `AtomFeed`
68
+ - **Sitemaps** - XML sitemap generation with `Sitemap`, `SitemapIndex`
69
+ - **Structured Data** - Schema.org markup with `Schema`
70
+ - **Open Graph & Twitter Cards** - Social meta tags with `OpenGraph`, `TwitterCard`
71
+
72
+ ### Security
73
+
74
+ - **CSRF Protection** - Token generation and validation
75
+ - **HTML Sanitization** - Safe HTML rendering with `sanitize_html`, `escape_html`
76
+ - **Password Hashing** - Secure password storage with `hash_password`, `verify_password`
77
+ - **Rate Limiting** - Request throttling with `RateLimiter`
78
+ - **CSP Headers** - Content Security Policy generation
79
+
80
+ ### Advanced Features
81
+
82
+ - **Web Components** - Custom elements with shadow DOM via `CustomElement`, `define_element`
83
+ - **WebSocket** - Real-time communication with `WebSocket`, `Channel`
84
+ - **ORM** - Database models with `Model`, `Field`, `QuerySet`
85
+ - **Authentication** - User auth with `Auth`, `login_user`, `logout_user`, `@login_required`
86
+ - **File Uploads** - Handle file uploads with `FileUpload`, `UploadedFile`
87
+ - **Caching** - LRU cache and memoization with `Cache`, `memoize`, `LRUCache`
88
+ - **Charts** - Data visualization with `Chart`, `BarChart`, `LineChart`, `PieChart`
89
+ - **PDF Generation** - Convert HTML to PDF with `PDF`, `html_to_pdf`
90
+ - **Email** - Email composition with `Email`, `EmailTemplate`
91
+ - **GraphQL** - GraphQL client with `GraphQLClient`, `query`, `mutation`
92
+ - **Middleware** - Request/response middleware with `MiddlewareStack`
93
+
94
+ ### Developer Tools
95
+
96
+ - **Testing** - Test utilities with `TestCase`, `TestClient`, `TestResponse`
97
+ - **Assertions** - DOM assertions with `ElementAssert`, `DocumentAssert`
98
+ - **Mock Server** - API mocking with `MockServer`, `MockResponse`
99
+ - **Debugging** - Debug tools with `inspect`, `tree`, `stats`, `validate_html`
100
+ - **Benchmarks** - Performance testing with `Benchmark`, `benchmark_render`
101
+ - **Pretty Print** - Formatted HTML output with `pretty_print`
102
+ - **Markdown** - Markdown parsing with `markdown_to_html`, `Markdown`
103
+ - **Export** - Data export to CSV, TSV, JSON, XML, Excel with `to_csv`, `to_excel`
104
+ - **Analytics** - Analytics integration with `GoogleAnalytics`, `PlausibleAnalytics`
105
+
106
+ ## WSGI Integration
107
+
108
+ ```python
109
+ from palestine import Document, html_response
110
+
111
+ def app(environ, start_response):
112
+ doc = Document()
113
+ # ... build your page
114
+ return html_response(doc, start_response)
115
+ ```
116
+
117
+ ## License
118
+
119
+ MIT
@@ -0,0 +1,120 @@
1
+ """
2
+ Palestine - A full spec DOM implementation in Python.
3
+
4
+ Usage:
5
+ from palestine import Document, Button, Div, Span
6
+
7
+ doc = Document()
8
+ body = doc.create_element('body')
9
+ doc.append_child(body)
10
+
11
+ btn = Button(type="submit", class_="primary")
12
+ btn.append_child(Text("Click me"))
13
+ body.append_child(btn)
14
+
15
+ print(doc)
16
+ # <!DOCTYPE html>
17
+ # <html><body><button type="submit" class="primary">Click me</button></body></html>
18
+ """
19
+
20
+ # Core
21
+ from .nodes import Node, Element, Text, Comment, Document
22
+ from .elements import create_element
23
+ from .constants import HTML5_ELEMENTS
24
+ from .events import Event, EventTarget
25
+ from .parse import parse_html, parse_fragment
26
+ from .render import render_element, render_node, minify
27
+
28
+ # Template and component
29
+ from .template import Template, TemplateError
30
+ from .component import Component, component, create_component, register_component
31
+ from .diff import Patch, diff, apply_patches
32
+
33
+ # Testing and serialization
34
+ from .assertions import ElementAssert, DocumentAssert, assert_element, assert_page, AssertionError
35
+ from .serialize import to_json, from_json, form_data, set_form_data, to_query_string
36
+ from .pretty import pretty_print, INLINE_ELEMENTS
37
+ from .wsgi import HTMLResponse, html_response, ahtml
38
+
39
+ # Advanced features
40
+ from .reactive import Signal, Computed, Effect, signal, computed, effect, batch
41
+ from .validate import (
42
+ Validator, Required, MinLength, MaxLength, Length, Pattern,
43
+ Email, URL, Number, Integer, OneOf, Custom, FormValidator,
44
+ ValidationError, validate_email, validate_url, validate_required, validate_length
45
+ )
46
+ from .route import Route, Router, RouteNotFoundError, link_element
47
+ from .styled import Styles, StyledElement, styled, Box, Flex, Grid, Text as StyledText
48
+ from .animate import (
49
+ Animation, Transition, animate, fade_in, fade_out, slide_in, scale_in, transition,
50
+ FADE_IN, FADE_OUT, SLIDE_IN_LEFT, SLIDE_IN_RIGHT, SLIDE_IN_UP, SLIDE_IN_DOWN,
51
+ SCALE_IN, SCALE_OUT, ROTATE, BOUNCE, PULSE, SHAKE,
52
+ get_animation_css, inject_animation_css
53
+ )
54
+ from .i18n import I18n, i18n_element, create_i18n, COMMON_TRANSLATIONS
55
+ from .vdom import VNode, VPatch, h, render_vdom, diff_vdom, patch
56
+ from .markdown import markdown_to_elements, markdown_to_html, Markdown
57
+ from .feed import FeedItem, RSSFeed, AtomFeed
58
+ from .sitemap import SitemapEntry, Sitemap, SitemapIndex
59
+ from .structured import Schema
60
+ from .og import OpenGraph, TwitterCard
61
+ from .debug import inspect, tree, stats, validate_html, diff_render, print_tree, print_stats
62
+ from .benchmark import (
63
+ Benchmark, benchmark_render, benchmark_parse, benchmark_minify,
64
+ create_deep_tree, create_wide_tree, run_default_benchmarks, print_benchmarks
65
+ )
66
+
67
+ # New modules
68
+ from .webcomponent import CustomElement, custom_element, define_element, get_element, create_custom_element, Slot, ShadowRoot
69
+ from .store import Store, Action, create_store, combine_reducers, create_action, logging_middleware, thunk_middleware, create_reducer
70
+ from .forms import FormBuilder
71
+ from .table import DataTable, Column
72
+ from .export import to_csv, to_tsv, to_json as export_json, to_xml, to_excel, Exporter
73
+ from .cache import Cache, memoize, cache_page, LRUCache
74
+ from .security import (
75
+ generate_csrf_token, validate_csrf_token, sanitize_html, escape_html,
76
+ hash_password, verify_password, generate_token, constant_time_compare,
77
+ RateLimiter, generate_csp_header, get_default_csp
78
+ )
79
+ from .seo import SEO, generate_sitemap, generate_robots_txt, generate_breadcrumb_schema
80
+ from .pwa import PWA, generate_service_worker, generate_service_worker_registration
81
+
82
+ # Additional modules
83
+ from .chart import Chart, BarChart, LineChart, PieChart, DoughnutChart, ScatterChart
84
+ from .pdf import PDF, html_to_pdf, element_to_pdf
85
+ from .email import Email, EmailTemplate, WELCOME_EMAIL, PASSWORD_RESET_EMAIL, VERIFICATION_EMAIL
86
+ from .graphql import Query, GraphQLClient, gql, query, mutation
87
+ from .websocket import WebSocket, Channel, Socket
88
+ from .orm import Field, QuerySet, Model, create_model
89
+ from .auth import User, Auth, init_auth, get_auth, login_user, logout_user, current_user, login_required, role_required
90
+ from .upload import UploadedFile, FileUpload, IMAGE_TYPES, VIDEO_TYPES, AUDIO_TYPES, DOCUMENT_TYPES
91
+ from .test_utils import TestCase, TestClient, TestResponse, Fixtures
92
+ from .mock import MockServer, MockResponse, create_mock_server
93
+ from .middleware import Middleware, MiddlewareStack, CORSMiddleware, LoggingMiddleware, CSRFMiddleware, SecurityHeadersMiddleware, AuthMiddleware
94
+ from .analytics import Analytics, GoogleAnalytics, GoogleTagManager, PlausibleAnalytics, create_analytics
95
+ from .types import HTMLTag, CSSProperty, EventType, ARIARole
96
+
97
+ # Import all element classes for direct use
98
+ from .elements import (
99
+ Html, Head, Title, Base, Link, Meta, Style,
100
+ Body, Article, Section, Nav, Aside,
101
+ H1, H2, H3, H4, H5, H6,
102
+ Header, Footer, Main, Address,
103
+ P, Hr, Pre, Blockquote, Ol, Ul, Li, Dl, Dt, Dd,
104
+ Figure, Figcaption, Div,
105
+ A, Em, Strong, Small, S, Cite, Q, Dfn, Abbr,
106
+ Ruby, Rt, Rp, Time, Code, Var, Samp, Kbd,
107
+ Sub, Sup, I, B, U, Mark, Bdi, Bdo, Span, Br, Wbr,
108
+ Area, Ins, Del,
109
+ Img, Iframe, Embed, Object, Param,
110
+ Video, Audio, Source, Track, Map, Picture, Canvas,
111
+ Script, Noscript, TemplateElement, Slot as ElementSlot,
112
+ Table, Caption, Colgroup, Col,
113
+ Tbody, Thead, Tfoot, Tr, Td, Th,
114
+ Form, Label, Input, Button, Select, Datalist,
115
+ Optgroup, Option, Textarea, Output, Progress,
116
+ Meter, Fieldset, Legend,
117
+ Details, Summary, Dialog, Menu, Search, Hgroup, Data,
118
+ )
119
+
120
+ __version__ = "0.1.0"
@@ -0,0 +1,144 @@
1
+ """Analytics integration for India DOM implementation.
2
+
3
+ Provides analytics tracking.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import Optional
9
+
10
+
11
+ class Analytics:
12
+ """Base analytics tracker."""
13
+
14
+ def __init__(self, tracking_id: str = "") -> None:
15
+ self._tracking_id = tracking_id
16
+ self._enabled = bool(tracking_id)
17
+
18
+ def track_pageview(self, path: str, title: str = "") -> None:
19
+ """Track page view."""
20
+ pass
21
+
22
+ def track_event(self, category: str, action: str,
23
+ label: str = "", value: int = 0) -> None:
24
+ """Track event."""
25
+ pass
26
+
27
+ def track_error(self, message: str, fatal: bool = False) -> None:
28
+ """Track error."""
29
+ pass
30
+
31
+ def track_timing(self, category: str, variable: str, time: int) -> None:
32
+ """Track timing."""
33
+ pass
34
+
35
+ def to_elements(self) -> list:
36
+ """Generate tracking script elements."""
37
+ return []
38
+
39
+
40
+ class GoogleAnalytics(Analytics):
41
+ """Google Analytics tracker."""
42
+
43
+ def __init__(self, tracking_id: str = "") -> None:
44
+ super().__init__(tracking_id)
45
+
46
+ def track_pageview(self, path: str, title: str = "") -> None:
47
+ """Track page view."""
48
+ # Would send to Google Analytics
49
+ pass
50
+
51
+ def track_event(self, category: str, action: str,
52
+ label: str = "", value: int = 0) -> None:
53
+ """Track event."""
54
+ pass
55
+
56
+ def to_elements(self) -> list:
57
+ """Generate GA tracking script."""
58
+ from .elements import Script
59
+
60
+ if not self._enabled:
61
+ return []
62
+
63
+ script = Script()
64
+ script.set_attribute("async", True)
65
+ script.set_attribute("src", f"https://www.googletagmanager.com/gtag/js?id={self._tracking_id}")
66
+
67
+ inline_script = Script()
68
+ from .nodes import Text
69
+ inline_script.append_child(Text(f"""
70
+ window.dataLayer = window.dataLayer || [];
71
+ function gtag(){{dataLayer.push(arguments);}}
72
+ gtag('js', new Date());
73
+ gtag('config', '{self._tracking_id}');
74
+ """))
75
+
76
+ return [script, inline_script]
77
+
78
+
79
+ class GoogleTagManager(Analytics):
80
+ """Google Tag Manager tracker."""
81
+
82
+ def __init__(self, container_id: str = "") -> None:
83
+ super().__init__(container_id)
84
+
85
+ def to_elements(self) -> list:
86
+ """Generate GTM tracking script."""
87
+ from .elements import Script, Noscript
88
+
89
+ if not self._enabled:
90
+ return []
91
+
92
+ script = Script()
93
+ from .nodes import Text
94
+ from .elements import create_element
95
+ script.append_child(Text(f"""
96
+ (function(w,d,s,l,i){{w[l]=w[l]||[];w[l].push({{'gtm.start':
97
+ new Date().getTime(),event:'gtm.js'}});var f=d.getElementsByTagName(s)[0],
98
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
99
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
100
+ }})(window,document,'script','dataLayer','{self._tracking_id}');
101
+ """))
102
+
103
+ noscript = Noscript()
104
+ iframe = create_element("iframe")
105
+ iframe.set_attribute("src", f"https://www.googletagmanager.com/ns.html?id={self._tracking_id}")
106
+ iframe.set_attribute("height", "0")
107
+ iframe.set_attribute("width", "0")
108
+ iframe.set_attribute("style", "display:none;visibility:hidden")
109
+ noscript.append_child(iframe)
110
+
111
+ return [script, noscript]
112
+
113
+
114
+ class PlausibleAnalytics(Analytics):
115
+ """Plausible Analytics tracker."""
116
+
117
+ def __init__(self, domain: str = "", data_api: str = "") -> None:
118
+ super().__init__(domain)
119
+ self._data_api = data_api
120
+
121
+ def to_elements(self) -> list:
122
+ """Generate Plausible tracking script."""
123
+ from .elements import Script
124
+
125
+ if not self._enabled:
126
+ return []
127
+
128
+ script = Script()
129
+ script.set_attribute("defer", True)
130
+ script.set_attribute("data-domain", self._tracking_id)
131
+ script.set_attribute("src", "https://plausible.io/js/script.js")
132
+
133
+ return [script]
134
+
135
+
136
+ def create_analytics(tracking_type: str = "ga", tracking_id: str = "") -> Analytics:
137
+ """Create analytics instance."""
138
+ if tracking_type == "ga":
139
+ return GoogleAnalytics(tracking_id)
140
+ elif tracking_type == "gtm":
141
+ return GoogleTagManager(tracking_id)
142
+ elif tracking_type == "plausible":
143
+ return PlausibleAnalytics(tracking_id)
144
+ return Analytics(tracking_id)