@flipova/foundation 1.13.0 → 2.0.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.
- package/CHANGELOG.md +181 -0
- package/README.md +53 -178
- package/components/ui/accordion/ANIMATION_CUSTOMIZATION.md +162 -0
- package/components/ui/accordion/AccordionAnimatedHeight.tsx +56 -0
- package/components/ui/accordion/AccordionAnimatedIcon.tsx +41 -0
- package/components/ui/accordion/AnimatedHeight.tsx +56 -0
- package/components/ui/accordion/AnimatedIcon.tsx +41 -0
- package/components/ui/accordion/MIGRATION_SUMMARY.md +250 -0
- package/components/ui/accordion/USAGE_EXAMPLE.tsx +179 -0
- package/components/ui/accordion/animation-config.ts +32 -0
- package/components/ui/accordion/index.tsx +253 -0
- package/components/ui/actionsheet/index.tsx +511 -0
- package/components/ui/alert/index.tsx +158 -0
- package/components/ui/alert-dialog/index.tsx +254 -0
- package/components/ui/avatar/index.tsx +139 -0
- package/components/ui/badge/index.tsx +163 -0
- package/components/ui/bottomsheet/index.tsx +477 -0
- package/components/ui/box/index.tsx +19 -0
- package/components/ui/box/index.web.tsx +19 -0
- package/components/ui/box/styles.tsx +10 -0
- package/components/ui/button/index.tsx +264 -0
- package/components/ui/calendar/creator.tsx +366 -0
- package/components/ui/calendar/index.tsx +462 -0
- package/components/ui/calendar/styles.tsx +140 -0
- package/components/ui/card/index.tsx +23 -0
- package/components/ui/card/index.web.tsx +26 -0
- package/components/ui/card/styles.tsx +16 -0
- package/components/ui/center/index.tsx +22 -0
- package/components/ui/center/index.web.tsx +20 -0
- package/components/ui/center/styles.tsx +8 -0
- package/components/ui/checkbox/index.tsx +184 -0
- package/components/ui/date-time-picker/creator.tsx +109 -0
- package/components/ui/date-time-picker/index.tsx +585 -0
- package/components/ui/date-time-picker/index.web.tsx +217 -0
- package/components/ui/date-time-picker/styles.tsx +56 -0
- package/components/ui/divider/index.tsx +40 -0
- package/components/ui/drawer/index.tsx +362 -0
- package/components/ui/fab/index.tsx +215 -0
- package/components/ui/flat-list/index.tsx +21 -0
- package/components/ui/form-control/index.tsx +352 -0
- package/components/ui/gluestack-ui-provider/config.ts +72 -0
- package/components/ui/gluestack-ui-provider/index.tsx +47 -0
- package/components/ui/gluestack-ui-provider/index.web.tsx +96 -0
- package/components/ui/gluestack-ui-provider/script.ts +19 -0
- package/components/ui/gluestack-ui-provider/tokens.d.ts +17 -0
- package/components/ui/gluestack-ui-provider/tokens.js +188 -0
- package/components/ui/gluestack-ui-provider/useGluestackColors.ts +82 -0
- package/components/ui/grid/index.tsx +283 -0
- package/components/ui/grid/index.web.tsx +66 -0
- package/components/ui/grid/styles.tsx +15 -0
- package/components/ui/heading/index.tsx +220 -0
- package/components/ui/heading/index.web.tsx +202 -0
- package/components/ui/heading/styles.tsx +43 -0
- package/components/ui/hstack/index.tsx +27 -0
- package/components/ui/hstack/index.web.tsx +26 -0
- package/components/ui/hstack/styles.tsx +25 -0
- package/components/ui/icon/index.tsx +1588 -0
- package/components/ui/icon/index.web.tsx +1573 -0
- package/components/ui/image/index.tsx +48 -0
- package/components/ui/image-background/index.tsx +25 -0
- package/components/ui/image-viewer/index.tsx +743 -0
- package/components/ui/image-viewer/index.web.tsx +302 -0
- package/components/ui/index.ts +58 -0
- package/components/ui/input/index.tsx +125 -0
- package/components/ui/input-accessory-view/index.tsx +2 -0
- package/components/ui/keyboard-avoiding-view/index.tsx +2 -0
- package/components/ui/link/index.tsx +102 -0
- package/components/ui/liquid-glass/index.tsx +74 -0
- package/components/ui/menu/index.tsx +186 -0
- package/components/ui/modal/index.tsx +237 -0
- package/components/ui/popover/index.tsx +272 -0
- package/components/ui/portal/index.tsx +17 -0
- package/components/ui/pressable/index.tsx +39 -0
- package/components/ui/progress/index.tsx +83 -0
- package/components/ui/radio/index.tsx +217 -0
- package/components/ui/refresh-control/index.tsx +2 -0
- package/components/ui/safe-area-view/index.tsx +2 -0
- package/components/ui/scroll-view/index.tsx +2 -0
- package/components/ui/section-list/index.tsx +2 -0
- package/components/ui/select/index.tsx +277 -0
- package/components/ui/select/select-actionsheet.tsx +562 -0
- package/components/ui/skeleton/index.tsx +105 -0
- package/components/ui/skeleton/index.web.tsx +103 -0
- package/components/ui/skeleton/styles.tsx +35 -0
- package/components/ui/slider/index.tsx +181 -0
- package/components/ui/spinner/index.tsx +40 -0
- package/components/ui/status-bar/index.tsx +2 -0
- package/components/ui/switch/index.tsx +41 -0
- package/components/ui/table/index.tsx +210 -0
- package/components/ui/table/index.web.tsx +157 -0
- package/components/ui/table/styles.tsx +44 -0
- package/components/ui/tabs/TabsAnimatedIndicator.tsx +160 -0
- package/components/ui/tabs/animation-config.ts +3 -0
- package/components/ui/tabs/creator.tsx +206 -0
- package/components/ui/tabs/index.tsx +484 -0
- package/components/ui/text/index.tsx +48 -0
- package/components/ui/text/index.web.tsx +45 -0
- package/components/ui/text/styles.tsx +47 -0
- package/components/ui/textarea/index.tsx +94 -0
- package/components/ui/toast/index.tsx +252 -0
- package/components/ui/tooltip/index.tsx +131 -0
- package/components/ui/view/index.tsx +2 -0
- package/components/ui/virtualized-list/index.tsx +2 -0
- package/components/ui/vstack/index.tsx +28 -0
- package/components/ui/vstack/index.web.tsx +27 -0
- package/components/ui/vstack/styles.tsx +25 -0
- package/design/canonical.index.txt +53 -0
- package/design/documentation.xml +519 -0
- package/design/manifest.xml +90 -0
- package/design/schema.xsd +639 -0
- package/design/themes.xml +204 -0
- package/design/tokens.xml +510 -0
- package/design/tools/design.js +165 -0
- package/design/tools/npm.js +65 -0
- package/design/tools/requirements.txt +35 -0
- package/design/tools/sources/.checker/__init__.py +81 -0
- package/design/tools/sources/.checker/checks.py +198 -0
- package/design/tools/sources/.checker/cli.py +154 -0
- package/design/tools/sources/.checker/io.py +242 -0
- package/design/tools/sources/.checker/model.py +144 -0
- package/design/tools/sources/.checker/registry.py +115 -0
- package/design/tools/sources/.checker/report.py +21 -0
- package/design/tools/sources/.docgen/__init__.py +45 -0
- package/design/tools/sources/.docgen/cli.py +101 -0
- package/design/tools/sources/.docgen/model.py +147 -0
- package/design/tools/sources/.docgen/reference.py +97 -0
- package/design/tools/sources/.docgen/site.py +145 -0
- package/design/tools/sources/.docgen/xsddoc.py +329 -0
- package/design/tools/sources/.generate/__init__.py +35 -0
- package/design/tools/sources/.generate/cli.py +76 -0
- package/design/tools/sources/.generate/common.py +33 -0
- package/design/tools/sources/.generate/config.py +119 -0
- package/design/tools/sources/.generate/model.py +51 -0
- package/design/tools/sources/.generate/tokens.py +141 -0
- package/design/tools/sources/.linter/__init__.py +9 -0
- package/design/tools/sources/.linter/cli.py +44 -0
- package/design/tools/sources/.linter/discovery.py +30 -0
- package/design/tools/sources/.linter/errors.py +45 -0
- package/design/tools/sources/.linter/linter.py +68 -0
- package/design/tools/sources/.xmleditor/__init__.py +74 -0
- package/design/tools/sources/.xmleditor/blocks.py +185 -0
- package/design/tools/sources/.xmleditor/cli.py +141 -0
- package/design/tools/sources/.xmleditor/editor.py +906 -0
- package/design/tools/sources/.xmleditor/model.py +708 -0
- package/design/tools/sources/.xmleditor/widgets.py +1832 -0
- package/design/tools/sources/.xmleditor/xsdmodel.py +753 -0
- package/design/tools/sources/checker.py +55 -0
- package/design/tools/sources/docgen.py +66 -0
- package/design/tools/sources/generate.py +48 -0
- package/design/tools/sources/linter.py +54 -0
- package/design/tools/sources/ruff.toml +12 -0
- package/design/tools/sources/xmleditor.py +62 -0
- package/design/tools/unix/_venv_python.sh +16 -0
- package/design/tools/unix/check.sh +13 -0
- package/design/tools/unix/doc.sh +14 -0
- package/design/tools/unix/gen.sh +14 -0
- package/design/tools/unix/lint.sh +10 -0
- package/design/tools/unix/run.sh +20 -0
- package/design/tools/unix/verify.sh +12 -0
- package/design/tools/unix/xmledit.sh +12 -0
- package/design/tools/windows/check.cmd +12 -0
- package/design/tools/windows/doc.cmd +12 -0
- package/design/tools/windows/gen.cmd +11 -0
- package/design/tools/windows/lint.cmd +9 -0
- package/design/tools/windows/run.cmd +26 -0
- package/design/tools/windows/verify.cmd +10 -0
- package/design/tools/windows/xmledit.cmd +10 -0
- package/dist/chunk-LV4UIEQN.js +9730 -0
- package/dist/chunk-LV4UIEQN.js.map +1 -0
- package/dist/chunk-WNVU3BM2.mjs +9401 -0
- package/dist/chunk-WNVU3BM2.mjs.map +1 -0
- package/dist/index.d.mts +40 -9
- package/dist/index.d.ts +40 -9
- package/dist/index.js +726 -414
- package/dist/index.mjs +1 -5
- package/dist/ui/index.d.mts +6931 -3070
- package/dist/ui/index.d.ts +6931 -3070
- package/dist/ui/index.js +779 -352
- package/dist/ui/index.mjs +1 -2
- package/package.json +66 -142
- package/dist/chunk-2XORADW6.js +0 -24552
- package/dist/chunk-2XORADW6.js.map +0 -1
- package/dist/chunk-52BHHF5M.js +0 -46
- package/dist/chunk-52BHHF5M.js.map +0 -1
- package/dist/chunk-5647JY7Z.mjs +0 -100
- package/dist/chunk-5647JY7Z.mjs.map +0 -1
- package/dist/chunk-5N5HC4ZA.mjs +0 -3
- package/dist/chunk-5N5HC4ZA.mjs.map +0 -1
- package/dist/chunk-7QFZMGL6.js +0 -8583
- package/dist/chunk-7QFZMGL6.js.map +0 -1
- package/dist/chunk-ASZEP37D.js +0 -423
- package/dist/chunk-ASZEP37D.js.map +0 -1
- package/dist/chunk-BH5SU2JQ.mjs +0 -8282
- package/dist/chunk-BH5SU2JQ.mjs.map +0 -1
- package/dist/chunk-BO65GO53.mjs +0 -422
- package/dist/chunk-BO65GO53.mjs.map +0 -1
- package/dist/chunk-BSVXX52E.mjs +0 -413
- package/dist/chunk-BSVXX52E.mjs.map +0 -1
- package/dist/chunk-DNV5UBNF.mjs +0 -3
- package/dist/chunk-DNV5UBNF.mjs.map +0 -1
- package/dist/chunk-EDTAMUO2.js +0 -8310
- package/dist/chunk-EDTAMUO2.js.map +0 -1
- package/dist/chunk-IJTI6EX4.js +0 -4
- package/dist/chunk-IJTI6EX4.js.map +0 -1
- package/dist/chunk-M3YLASM2.js +0 -428
- package/dist/chunk-M3YLASM2.js.map +0 -1
- package/dist/chunk-OXKOGLXE.js +0 -4
- package/dist/chunk-OXKOGLXE.js.map +0 -1
- package/dist/chunk-RQXQK3ZO.mjs +0 -8486
- package/dist/chunk-RQXQK3ZO.mjs.map +0 -1
- package/dist/chunk-SR25V4EA.mjs +0 -40
- package/dist/chunk-SR25V4EA.mjs.map +0 -1
- package/dist/chunk-UB34WFEQ.js +0 -106
- package/dist/chunk-UB34WFEQ.js.map +0 -1
- package/dist/chunk-ZBRWXKDF.mjs +0 -24431
- package/dist/chunk-ZBRWXKDF.mjs.map +0 -1
- package/dist/cli/ds.d.mts +0 -1
- package/dist/cli/ds.d.ts +0 -1
- package/dist/cli/ds.js +0 -602
- package/dist/cli/ds.js.map +0 -1
- package/dist/cli/ds.mjs +0 -579
- package/dist/cli/ds.mjs.map +0 -1
- package/dist/cli/flipova.d.mts +0 -1
- package/dist/cli/flipova.d.ts +0 -1
- package/dist/cli/flipova.js +0 -161
- package/dist/cli/flipova.js.map +0 -1
- package/dist/cli/flipova.mjs +0 -154
- package/dist/cli/flipova.mjs.map +0 -1
- package/dist/config/index.d.mts +0 -123
- package/dist/config/index.d.ts +0 -123
- package/dist/config/index.js +0 -28
- package/dist/config/index.js.map +0 -1
- package/dist/config/index.mjs +0 -3
- package/dist/config/index.mjs.map +0 -1
- package/dist/index-CuaJA3gM.d.mts +0 -78
- package/dist/index-CuaJA3gM.d.ts +0 -78
- package/dist/registry/index.d.mts +0 -10160
- package/dist/registry/index.d.ts +0 -10160
- package/dist/registry/index.js +0 -392
- package/dist/registry/index.js.map +0 -1
- package/dist/registry/index.mjs +0 -3
- package/dist/registry/index.mjs.map +0 -1
- package/dist/theme/index.d.mts +0 -109
- package/dist/theme/index.d.ts +0 -109
- package/dist/theme/index.js +0 -28
- package/dist/theme/index.js.map +0 -1
- package/dist/theme/index.mjs +0 -3
- package/dist/theme/index.mjs.map +0 -1
- package/dist/tokens/index.d.mts +0 -423
- package/dist/tokens/index.d.ts +0 -423
- package/dist/tokens/index.js +0 -44
- package/dist/tokens/index.js.map +0 -1
- package/dist/tokens/index.mjs +0 -3
- package/dist/tokens/index.mjs.map +0 -1
- package/dist/types/index.d.mts +0 -202
- package/dist/types/index.d.ts +0 -202
- package/dist/types/index.js +0 -4
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -3
- package/dist/types/index.mjs.map +0 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""Tailwind / nativewind token emitter (design/tokens.xml + themes.xml -> tokens.js).
|
|
2
|
+
|
|
3
|
+
Turns the registries into the whole Tailwind `theme.extend` fragment used by
|
|
4
|
+
tailwind.config.js:
|
|
5
|
+
|
|
6
|
+
- semantic colours, generated from the themes.xml roles and bound to the CSS
|
|
7
|
+
variables emitted in config.ts;
|
|
8
|
+
- the scale tokens (spacing, radii, breakpoints, typography, shadow, motion).
|
|
9
|
+
|
|
10
|
+
The `color` palette is deliberately NOT emitted: it is internal, and what
|
|
11
|
+
Tailwind needs are the semantic colours built on top of it.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from .common import *
|
|
17
|
+
from .config import _resolve_colour, _to_rgb_triplet, theme_role_ids
|
|
18
|
+
from .model import ManifestModel
|
|
19
|
+
|
|
20
|
+
_HEADER = [
|
|
21
|
+
"// Generated by design/tools/sources/generate.py -- do not edit by hand.",
|
|
22
|
+
"// Source of truth: design/tokens.xml + design/themes.xml",
|
|
23
|
+
"// Tailwind/nativewind theme, consumed by tailwind.config.js.",
|
|
24
|
+
"// Regenerate with: npm run design:gen",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _js_str(value: object) -> str:
|
|
29
|
+
text = str(value).replace("\\", "\\\\").replace("'", "\\'")
|
|
30
|
+
return f"'{text}'"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _text(elem) -> str:
|
|
34
|
+
return (elem.text or "").strip() if elem is not None else ""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _values(token):
|
|
38
|
+
values = token.find(q("values"))
|
|
39
|
+
return values.findall(q("value")) if values is not None else []
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _scaled(values, unit: str, default_unit: str = "px"):
|
|
43
|
+
unit = unit or default_unit
|
|
44
|
+
return [(v.get("id") or "", _js_str(f"{_text(v)}{unit}")) for v in values]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _shadow_entries(ctx: checker.RegistryModel, values):
|
|
48
|
+
entries = []
|
|
49
|
+
for v in values:
|
|
50
|
+
ref = v.find(q("color") + "/" + q("ref"))
|
|
51
|
+
hexv = _resolve_colour(ctx, _text(ref)) if ref is not None else "#000000"
|
|
52
|
+
rgb = _to_rgb_triplet(hexv)
|
|
53
|
+
x = _text(v.find(q("offset") + "/" + q("x"))) or "0"
|
|
54
|
+
y = _text(v.find(q("offset") + "/" + q("y"))) or "0"
|
|
55
|
+
radius = _text(v.find(q("radius"))) or "0"
|
|
56
|
+
opacity = _text(v.find(q("opacity"))) or "1"
|
|
57
|
+
entries.append((v.get("id") or "", _js_str(f"{x}px {y}px {radius}px rgb({rgb} / {opacity})")))
|
|
58
|
+
return entries
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _entry(ctx: checker.RegistryModel, token):
|
|
62
|
+
"""Map one token to (tailwindKey, [(valueId, jsExpr)]), or None to skip."""
|
|
63
|
+
tid = (token.get("id") or "").strip()
|
|
64
|
+
unit = (token.get("unit") or "").strip()
|
|
65
|
+
values = _values(token)
|
|
66
|
+
if tid == "spacing":
|
|
67
|
+
return "spacing", _scaled(values, unit)
|
|
68
|
+
if tid == "radii":
|
|
69
|
+
return "borderRadius", _scaled(values, unit)
|
|
70
|
+
if tid == "breakpoints":
|
|
71
|
+
return "screens", _scaled(values, unit)
|
|
72
|
+
if tid == "family":
|
|
73
|
+
items = []
|
|
74
|
+
for v in values:
|
|
75
|
+
families = [p.strip() for p in _text(v.find(q("web"))).split(",") if p.strip()]
|
|
76
|
+
items.append((v.get("id") or "", "[" + ", ".join(_js_str(f) for f in families) + "]"))
|
|
77
|
+
return "fontFamily", items
|
|
78
|
+
if tid == "fontSizes":
|
|
79
|
+
return "fontSize", _scaled(values, unit)
|
|
80
|
+
if tid == "fontWeights":
|
|
81
|
+
return "fontWeight", [(v.get("id") or "", _js_str(_text(v))) for v in values]
|
|
82
|
+
if tid == "lineHeights":
|
|
83
|
+
items = []
|
|
84
|
+
for v in values:
|
|
85
|
+
raw = _text(v)
|
|
86
|
+
try:
|
|
87
|
+
expr = _js_str(raw if float(raw) <= 2 else f"{raw}{unit or 'px'}")
|
|
88
|
+
except ValueError:
|
|
89
|
+
expr = _js_str(raw)
|
|
90
|
+
items.append((v.get("id") or "", expr))
|
|
91
|
+
return "lineHeight", items
|
|
92
|
+
if tid == "letterSpacings":
|
|
93
|
+
return "letterSpacing", _scaled(values, unit, "em")
|
|
94
|
+
if tid == "shadow":
|
|
95
|
+
return "boxShadow", _shadow_entries(ctx, values)
|
|
96
|
+
if tid == "zIndex":
|
|
97
|
+
return "zIndex", [(v.get("id") or "", _js_str(_text(v))) for v in values]
|
|
98
|
+
if tid == "opacity":
|
|
99
|
+
return "opacity", [(v.get("id") or "", _js_str(_text(v))) for v in values]
|
|
100
|
+
if tid == "duration":
|
|
101
|
+
return "transitionDuration", _scaled(values, unit or "ms", "ms")
|
|
102
|
+
if tid == "easing":
|
|
103
|
+
items = []
|
|
104
|
+
for v in values:
|
|
105
|
+
web = _text(v.find(q("web")))
|
|
106
|
+
if not web or web == "spring":
|
|
107
|
+
continue # not a CSS timing function
|
|
108
|
+
items.append((v.get("id") or "", _js_str(web)))
|
|
109
|
+
return "transitionTimingFunction", items
|
|
110
|
+
# `color` (palette) is skipped on purpose: semantic colours live in config.ts.
|
|
111
|
+
return None
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def render_tokens_theme(man: ManifestModel) -> str:
|
|
115
|
+
tokens_path = man.ctx.catalog_files.get("tokens")
|
|
116
|
+
if tokens_path is None or not tokens_path.exists():
|
|
117
|
+
raise SystemExit("manifest: no tokens catalog file found")
|
|
118
|
+
root = etree.parse(str(tokens_path)).getroot()
|
|
119
|
+
groups: list[tuple[str, list[tuple[str, str]]]] = []
|
|
120
|
+
# Semantic colours first: one Tailwind colour per themes.xml role, bound to
|
|
121
|
+
# the CSS variable emitted in config.ts (so `bg-primary/50` keeps working).
|
|
122
|
+
roles = theme_role_ids(man)
|
|
123
|
+
if roles:
|
|
124
|
+
groups.append(("colors", [
|
|
125
|
+
(rid, _js_str(f"rgb(var(--{rid})/<alpha-value>)")) for rid in roles
|
|
126
|
+
]))
|
|
127
|
+
for token in root.findall(q("items") + "/" + q("token")):
|
|
128
|
+
entry = _entry(man.ctx, token)
|
|
129
|
+
if entry is not None:
|
|
130
|
+
groups.append(entry)
|
|
131
|
+
lines = list(_HEADER)
|
|
132
|
+
lines.append("module.exports = {")
|
|
133
|
+
lines.append(" theme: {")
|
|
134
|
+
for key, items in groups:
|
|
135
|
+
lines.append(f" {key}: {{")
|
|
136
|
+
for ident, expr in items:
|
|
137
|
+
lines.append(f" {_js_str(ident)}: {expr},")
|
|
138
|
+
lines.append(" },")
|
|
139
|
+
lines.append(" },")
|
|
140
|
+
lines.append("};")
|
|
141
|
+
return "\n".join(lines) + "\n"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .cli import main
|
|
4
|
+
from .discovery import discover_xml_files
|
|
5
|
+
from .errors import LintResult, ValidationError
|
|
6
|
+
from .linter import XSDLinter
|
|
7
|
+
|
|
8
|
+
__all__ = ["LintResult", "ValidationError", "XSDLinter", "discover_xml_files", "main"]
|
|
9
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from .discovery import discover_xml_files
|
|
8
|
+
from .errors import LintResult
|
|
9
|
+
from .linter import XSDLinter
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main() -> int:
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
description="XSD linter (agnostic)"
|
|
15
|
+
)
|
|
16
|
+
parser.add_argument("files", nargs="*", help="XML files to validate")
|
|
17
|
+
parser.add_argument("--schema", "-s", help="Path to XSD schema")
|
|
18
|
+
parser.add_argument("--manifest", "-m", help="Validate files from manifest")
|
|
19
|
+
parser.add_argument("--dir", "-d", help="Validate all XML in directory")
|
|
20
|
+
parser.add_argument("--verbose", "-v", action="store_true")
|
|
21
|
+
args = parser.parse_args()
|
|
22
|
+
files_to_check = []
|
|
23
|
+
if args.manifest:
|
|
24
|
+
files_to_check.extend(discover_xml_files(args.manifest))
|
|
25
|
+
if args.dir:
|
|
26
|
+
files_to_check.extend(str(f) for f in Path(args.dir).glob("*.xml"))
|
|
27
|
+
files_to_check.extend(args.files)
|
|
28
|
+
files_to_check = list(dict.fromkeys(files_to_check))
|
|
29
|
+
if not files_to_check:
|
|
30
|
+
parser.error("No files to validate")
|
|
31
|
+
linter = XSDLinter(schema_path=args.schema)
|
|
32
|
+
total = LintResult()
|
|
33
|
+
for xml_file in files_to_check:
|
|
34
|
+
result = linter.validate_file(xml_file)
|
|
35
|
+
total.merge(result)
|
|
36
|
+
if args.verbose or result.errors:
|
|
37
|
+
print(f"--- {xml_file} ---")
|
|
38
|
+
for err in result.errors:
|
|
39
|
+
print(f" {err}")
|
|
40
|
+
if not result.errors:
|
|
41
|
+
print(" OK")
|
|
42
|
+
print()
|
|
43
|
+
print(total.summary())
|
|
44
|
+
sys.exit(0 if total.success else 1)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from lxml import etree
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def discover_xml_files(manifest_path: str) -> list:
|
|
9
|
+
"""Catalog-driven discovery: <file> entries plus <dir> templates.
|
|
10
|
+
|
|
11
|
+
Stays agnostic: the manifest alone decides what gets validated; a <dir>
|
|
12
|
+
template is a path pattern with a {Name} placeholder (expanded to '*').
|
|
13
|
+
"""
|
|
14
|
+
xml_files = []
|
|
15
|
+
manifest_dir = str(Path(manifest_path).parent)
|
|
16
|
+
try:
|
|
17
|
+
doc = etree.parse(manifest_path)
|
|
18
|
+
except etree.XMLSyntaxError:
|
|
19
|
+
return xml_files
|
|
20
|
+
for elem in doc.iter():
|
|
21
|
+
tag = etree.QName(elem.tag).localname if "{" in elem.tag else elem.tag
|
|
22
|
+
if tag == "catalog":
|
|
23
|
+
file_elem = elem.find("{urn:flipova:foundation:registry}file")
|
|
24
|
+
if file_elem is not None and file_elem.text:
|
|
25
|
+
xml_files.append(str(Path(manifest_dir) / file_elem.text))
|
|
26
|
+
dir_elem = elem.find("{urn:flipova:foundation:registry}dir")
|
|
27
|
+
if dir_elem is not None and dir_elem.text:
|
|
28
|
+
pattern = dir_elem.text.strip().replace("{Name}", "*")
|
|
29
|
+
xml_files.extend(str(p) for p in sorted(Path(manifest_dir).glob(pattern)))
|
|
30
|
+
return sorted(set(xml_files))
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class ValidationError:
|
|
8
|
+
file: str
|
|
9
|
+
line: int | None
|
|
10
|
+
column: int | None
|
|
11
|
+
message: str
|
|
12
|
+
severity: str = "error"
|
|
13
|
+
|
|
14
|
+
def __str__(self) -> str:
|
|
15
|
+
loc = f"{self.file}"
|
|
16
|
+
if self.line is not None:
|
|
17
|
+
loc += f":{self.line}"
|
|
18
|
+
if self.column is not None:
|
|
19
|
+
loc += f":{self.column}"
|
|
20
|
+
return f"[{self.severity.upper()}] {loc}: {self.message}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class LintResult:
|
|
25
|
+
errors: list = field(default_factory=list)
|
|
26
|
+
files_checked: int = 0
|
|
27
|
+
files_valid: int = 0
|
|
28
|
+
files_invalid: int = 0
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def success(self) -> bool:
|
|
32
|
+
return self.files_invalid == 0
|
|
33
|
+
|
|
34
|
+
def merge(self, other: LintResult) -> None:
|
|
35
|
+
self.errors.extend(other.errors)
|
|
36
|
+
self.files_checked += other.files_checked
|
|
37
|
+
self.files_valid += other.files_valid
|
|
38
|
+
self.files_invalid += other.files_invalid
|
|
39
|
+
|
|
40
|
+
def summary(self) -> str:
|
|
41
|
+
return (
|
|
42
|
+
f"Files checked: {self.files_checked}\n"
|
|
43
|
+
f"Valid: {self.files_valid}\n"
|
|
44
|
+
f"Invalid: {self.files_invalid}"
|
|
45
|
+
)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from lxml import etree
|
|
6
|
+
|
|
7
|
+
from .errors import LintResult, ValidationError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class XSDLinter:
|
|
11
|
+
"""Generic XML Schema linter - agnostic, no domain knowledge."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, schema_path: str | None = None):
|
|
14
|
+
self._schema: etree.XMLSchema | None = None
|
|
15
|
+
if schema_path:
|
|
16
|
+
self.load_schema(schema_path)
|
|
17
|
+
|
|
18
|
+
def load_schema(self, schema_path: str) -> None:
|
|
19
|
+
try:
|
|
20
|
+
schema_doc = etree.parse(schema_path)
|
|
21
|
+
self._schema = etree.XMLSchema(schema_doc)
|
|
22
|
+
except etree.XMLSchemaParseError as e:
|
|
23
|
+
raise ValueError(f"Invalid XSD schema: {e}") from e
|
|
24
|
+
|
|
25
|
+
def validate_file(self, xml_path: str) -> LintResult:
|
|
26
|
+
result = LintResult()
|
|
27
|
+
result.files_checked = 1
|
|
28
|
+
try:
|
|
29
|
+
doc = etree.parse(xml_path)
|
|
30
|
+
except etree.XMLSyntaxError as e:
|
|
31
|
+
result.errors.append(ValidationError(
|
|
32
|
+
file=xml_path, line=e.lineno, column=e.offset,
|
|
33
|
+
message=f"Malformed XML: {e.msg}"
|
|
34
|
+
))
|
|
35
|
+
result.files_invalid = 1
|
|
36
|
+
return result
|
|
37
|
+
if self._schema is None:
|
|
38
|
+
schemaLocation = doc.getroot().get(
|
|
39
|
+
"{http://www.w3.org/2001/XMLSchema-instance}schemaLocation"
|
|
40
|
+
)
|
|
41
|
+
if schemaLocation:
|
|
42
|
+
parts = schemaLocation.split()
|
|
43
|
+
if len(parts) >= 2:
|
|
44
|
+
schema_dir = Path(xml_path).parent
|
|
45
|
+
schema_file = schema_dir / parts[-1]
|
|
46
|
+
if schema_file.exists():
|
|
47
|
+
self.load_schema(str(schema_file))
|
|
48
|
+
if self._schema is None:
|
|
49
|
+
result.errors.append(ValidationError(
|
|
50
|
+
file=xml_path, line=None, column=None,
|
|
51
|
+
message="No schema available",
|
|
52
|
+
severity="warning"
|
|
53
|
+
))
|
|
54
|
+
result.files_valid = 1
|
|
55
|
+
return result
|
|
56
|
+
try:
|
|
57
|
+
self._schema.assertValid(doc)
|
|
58
|
+
result.files_valid = 1
|
|
59
|
+
except etree.DocumentInvalid:
|
|
60
|
+
for log_entry in self._schema.error_log:
|
|
61
|
+
result.errors.append(ValidationError(
|
|
62
|
+
file=log_entry.filename or xml_path,
|
|
63
|
+
line=log_entry.line,
|
|
64
|
+
column=log_entry.column,
|
|
65
|
+
message=log_entry.message,
|
|
66
|
+
))
|
|
67
|
+
result.files_invalid = 1
|
|
68
|
+
return result
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Visual, XSD-driven XML block editor (implementation package).
|
|
2
|
+
|
|
3
|
+
Split out of a single script for modularity:
|
|
4
|
+
|
|
5
|
+
- ``xsdmodel.py`` : XSD introspection -> SchemaModel (roots, blocks, nested
|
|
6
|
+
particles with real cardinality, attributes, enumerations,
|
|
7
|
+
xs:group / xs:attributeGroup, complexContent extension,
|
|
8
|
+
simpleContent, xs:any, xs:documentation)
|
|
9
|
+
- ``blocks.py`` : block profile + contextual palette (what may go where)
|
|
10
|
+
- ``model.py`` : editable document (lxml), undo/redo, structural checks and
|
|
11
|
+
authoritative XSD validation via design/tools/sources/linter.py
|
|
12
|
+
- ``widgets.py`` : ttk widgets (palette, block tree, UML-ish diagram,
|
|
13
|
+
typed inspector, source view)
|
|
14
|
+
- ``editor.py`` : main window
|
|
15
|
+
- ``cli.py`` : CLI and headless modes (``main``)
|
|
16
|
+
|
|
17
|
+
``widgets``/``editor`` need a GUI toolkit and are therefore imported lazily by
|
|
18
|
+
the CLI, so every headless mode works on machines without tkinter.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
from .blocks import (
|
|
24
|
+
PaletteEntry,
|
|
25
|
+
can_add,
|
|
26
|
+
contextual_entries,
|
|
27
|
+
describe,
|
|
28
|
+
missing_required,
|
|
29
|
+
profile_categories,
|
|
30
|
+
unfulfilled_required_attributes,
|
|
31
|
+
)
|
|
32
|
+
from .cli import DEFAULT_SCHEMA, main
|
|
33
|
+
from .model import XML_DECLARATION, DocumentModel, Issue
|
|
34
|
+
from .xsdmodel import (
|
|
35
|
+
AttributeSpec,
|
|
36
|
+
BlockSpec,
|
|
37
|
+
LeafSpec,
|
|
38
|
+
ParticleSpec,
|
|
39
|
+
SchemaModel,
|
|
40
|
+
format_occurs,
|
|
41
|
+
load_schema,
|
|
42
|
+
localname,
|
|
43
|
+
node_key,
|
|
44
|
+
xs,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
# cli
|
|
49
|
+
"DEFAULT_SCHEMA",
|
|
50
|
+
"XML_DECLARATION",
|
|
51
|
+
# xsdmodel
|
|
52
|
+
"AttributeSpec",
|
|
53
|
+
"BlockSpec",
|
|
54
|
+
# model
|
|
55
|
+
"DocumentModel",
|
|
56
|
+
"Issue",
|
|
57
|
+
"LeafSpec",
|
|
58
|
+
# blocks
|
|
59
|
+
"PaletteEntry",
|
|
60
|
+
"ParticleSpec",
|
|
61
|
+
"SchemaModel",
|
|
62
|
+
"can_add",
|
|
63
|
+
"contextual_entries",
|
|
64
|
+
"describe",
|
|
65
|
+
"format_occurs",
|
|
66
|
+
"load_schema",
|
|
67
|
+
"localname",
|
|
68
|
+
"main",
|
|
69
|
+
"missing_required",
|
|
70
|
+
"node_key",
|
|
71
|
+
"profile_categories",
|
|
72
|
+
"unfulfilled_required_attributes",
|
|
73
|
+
"xs",
|
|
74
|
+
]
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"""Block profile — the palette and the contextual "what may go here?" engine.
|
|
2
|
+
|
|
3
|
+
Everything here is computed from ``SchemaModel``: block categories, addable
|
|
4
|
+
children, cardinality limits and tooltips. There is no table of component or
|
|
5
|
+
attribute names anywhere in the editor, so extending ``design/schema.xsd``
|
|
6
|
+
extends the GUI with no code change.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections import OrderedDict
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from typing import Sequence
|
|
14
|
+
|
|
15
|
+
from .xsdmodel import UNBOUNDED, BlockSpec, ParticleSpec, SchemaModel, format_occurs
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class PaletteEntry:
|
|
20
|
+
"""One addable block, with the context that made it available."""
|
|
21
|
+
|
|
22
|
+
block: BlockSpec
|
|
23
|
+
particle: ParticleSpec | None = None
|
|
24
|
+
category: str = ""
|
|
25
|
+
reason: str = ""
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def label(self) -> str:
|
|
29
|
+
if self.block.name == "*":
|
|
30
|
+
return "+ free key…"
|
|
31
|
+
return self.block.name
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def detail(self) -> str:
|
|
35
|
+
parts: list[str] = []
|
|
36
|
+
if self.particle is not None:
|
|
37
|
+
parts.append(format_occurs(self.particle.min_occurs, self.particle.max_occurs))
|
|
38
|
+
if self.particle.via_choice:
|
|
39
|
+
parts.append("choice")
|
|
40
|
+
if self.particle.via_ref:
|
|
41
|
+
parts.append("ref")
|
|
42
|
+
if self.block.type_name:
|
|
43
|
+
parts.append(self.block.type_name)
|
|
44
|
+
return " · ".join(parts)
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def tooltip(self) -> str:
|
|
48
|
+
lines: list[str] = []
|
|
49
|
+
if self.reason:
|
|
50
|
+
lines.append(self.reason)
|
|
51
|
+
if self.particle is not None:
|
|
52
|
+
lines.append(f"allowed {self.particle.occurs_label}")
|
|
53
|
+
if self.block.type_name:
|
|
54
|
+
lines.append(f"type: {self.block.type_name}")
|
|
55
|
+
if self.block.documentation:
|
|
56
|
+
lines.append(self.block.documentation)
|
|
57
|
+
children = [p.name for p in self.block.children]
|
|
58
|
+
if children:
|
|
59
|
+
lines.append("children: {}".format(", ".join(children)))
|
|
60
|
+
if self.block.attributes:
|
|
61
|
+
lines.append("attributes: {}".format(", ".join(a.name for a in self.block.attributes)))
|
|
62
|
+
return "\n".join(lines)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def profile_categories(schema: SchemaModel) -> OrderedDict[str, list[BlockSpec]]:
|
|
66
|
+
"""Palette categories derived from the schema shape (XSD-only)."""
|
|
67
|
+
return schema.profile()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def can_add(particle: ParticleSpec, existing_count: int) -> bool:
|
|
71
|
+
"""True while the content model still accepts another copy."""
|
|
72
|
+
if particle.max_occurs is UNBOUNDED:
|
|
73
|
+
return True
|
|
74
|
+
return existing_count < particle.max_occurs
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def contextual_entries(
|
|
78
|
+
schema: SchemaModel,
|
|
79
|
+
block: BlockSpec | None,
|
|
80
|
+
child_names: Sequence[str],
|
|
81
|
+
) -> list[PaletteEntry]:
|
|
82
|
+
"""Blocks that may be inserted under *block*, given its current children.
|
|
83
|
+
|
|
84
|
+
``child_names`` is the list of element names already present (repeats
|
|
85
|
+
included), so cardinality limits are respected exactly. Missing required
|
|
86
|
+
blocks come first — the palette doubles as a completeness checklist.
|
|
87
|
+
"""
|
|
88
|
+
if block is None:
|
|
89
|
+
return [
|
|
90
|
+
PaletteEntry(block=root, category="Roots", reason="root element")
|
|
91
|
+
for root in schema.roots
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
counts: dict = {}
|
|
95
|
+
for name in child_names:
|
|
96
|
+
counts[name] = counts.get(name, 0) + 1
|
|
97
|
+
|
|
98
|
+
required: list[PaletteEntry] = []
|
|
99
|
+
allowed: list[PaletteEntry] = []
|
|
100
|
+
for particle in block.children:
|
|
101
|
+
current = counts.get(particle.name, 0)
|
|
102
|
+
if not can_add(particle, current):
|
|
103
|
+
continue
|
|
104
|
+
entry = PaletteEntry(block=particle.block, particle=particle)
|
|
105
|
+
if particle.required and current == 0:
|
|
106
|
+
entry.category = "Required"
|
|
107
|
+
entry.reason = "required by the schema"
|
|
108
|
+
required.append(entry)
|
|
109
|
+
else:
|
|
110
|
+
entry.category = "Allowed"
|
|
111
|
+
entry.reason = "allowed here"
|
|
112
|
+
allowed.append(entry)
|
|
113
|
+
|
|
114
|
+
if block.allows_any:
|
|
115
|
+
allowed.append(PaletteEntry(
|
|
116
|
+
block=BlockSpec(
|
|
117
|
+
name="*",
|
|
118
|
+
key="%s.*" % (block.key or block.name),
|
|
119
|
+
type_name="xs:any",
|
|
120
|
+
documentation="open content (xs:any): the schema lets you choose "
|
|
121
|
+
"the element name, the value follows the group's contract"),
|
|
122
|
+
category="Open content",
|
|
123
|
+
reason="the schema opens this group to free keys (xs:any)"))
|
|
124
|
+
|
|
125
|
+
return required + allowed
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def missing_required(block: BlockSpec, child_names: Sequence[str]) -> list[ParticleSpec]:
|
|
129
|
+
"""Required particles that have no occurrence yet."""
|
|
130
|
+
present = set(child_names)
|
|
131
|
+
return [p for p in block.children if p.required and p.name not in present]
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def unfulfilled_required_attributes(block: BlockSpec, attribute_names: Sequence[str]) -> list[str]:
|
|
135
|
+
"""Required attributes that are still absent on an element."""
|
|
136
|
+
present = set(attribute_names)
|
|
137
|
+
return [a.name for a in block.attributes if a.required and a.name not in present]
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def describe(block: BlockSpec) -> str:
|
|
141
|
+
"""Multi-line schema description used by the inspector pane."""
|
|
142
|
+
lines = ["{}{}".format(block.name, f" ({block.type_name})" if block.type_name else "")]
|
|
143
|
+
if block.key and block.key != block.name:
|
|
144
|
+
lines.append(f"key: {block.key}")
|
|
145
|
+
lines.append(f"kind: {block.kind}")
|
|
146
|
+
if block.mixed:
|
|
147
|
+
lines.append("content: mixed text + blocks")
|
|
148
|
+
if block.leaf is not None:
|
|
149
|
+
lines.append(f"value type: {block.leaf.base}")
|
|
150
|
+
if block.leaf.enumerations:
|
|
151
|
+
lines.append("allowed values: {}".format(", ".join(block.leaf.enumerations)))
|
|
152
|
+
if block.leaf.pattern:
|
|
153
|
+
lines.append(f"pattern: {block.leaf.pattern}")
|
|
154
|
+
if block.allows_any:
|
|
155
|
+
lines.append("content: xs:any (extension points allowed)")
|
|
156
|
+
if block.children:
|
|
157
|
+
lines.append("children:")
|
|
158
|
+
for particle in block.children:
|
|
159
|
+
marks = []
|
|
160
|
+
if particle.required:
|
|
161
|
+
marks.append("required")
|
|
162
|
+
if particle.repeatable:
|
|
163
|
+
marks.append("repeatable")
|
|
164
|
+
if particle.via_choice:
|
|
165
|
+
marks.append("choice")
|
|
166
|
+
suffix = " [{}]".format(", ".join(marks)) if marks else ""
|
|
167
|
+
lines.append(f" - {particle.name} {particle.occurs_label}{suffix}")
|
|
168
|
+
if block.attributes:
|
|
169
|
+
lines.append("attributes:")
|
|
170
|
+
for attr in block.attributes:
|
|
171
|
+
flags = [attr.use]
|
|
172
|
+
if attr.fixed is not None:
|
|
173
|
+
flags.append(f"fixed={attr.fixed}")
|
|
174
|
+
elif attr.default is not None:
|
|
175
|
+
flags.append(f"default={attr.default}")
|
|
176
|
+
if attr.enumerations:
|
|
177
|
+
flags.append("one of {}".format("|".join(attr.enumerations)))
|
|
178
|
+
if attr.pattern:
|
|
179
|
+
flags.append(f"pattern={attr.pattern}")
|
|
180
|
+
lines.append(" - {} ({})".format(attr.name, ", ".join(flags)))
|
|
181
|
+
if block.documentation:
|
|
182
|
+
lines.append("")
|
|
183
|
+
lines.append(block.documentation)
|
|
184
|
+
return "\n".join(lines)
|
|
185
|
+
|