@styleflow.app/flowpress-astro-core 0.2.0-beta.11 → 0.2.0-beta.2

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.
@@ -1,108 +0,0 @@
1
- import { resolveDynamicStyleflowProps } from "../../styleflow.js";
2
- export const DEFAULT_SEMANTIC_PROPS = {
3
- surface: "default",
4
- layoutRole: "stack",
5
- density: "md"
6
- };
7
- export function blockHtmlAttributes(attributes, baseClass = "") {
8
- const anchor = typeof attributes.anchor === "string"
9
- ? attributes.anchor.trim()
10
- : "";
11
- const customClass = typeof attributes.className === "string"
12
- ? attributes.className.trim()
13
- : "";
14
- const className = [baseClass.trim(), customClass]
15
- .filter(Boolean)
16
- .join(" ")
17
- .replace(/\s+/g, " ");
18
- return {
19
- ...(anchor ? { id: anchor } : {}),
20
- ...(className ? { class: className } : {})
21
- };
22
- }
23
- const SEMANTIC_KEYS = [
24
- "tone",
25
- "intensity",
26
- "surface",
27
- "layoutRole",
28
- "density",
29
- "ty",
30
- "v",
31
- "w",
32
- "foreground",
33
- "interactivePriority",
34
- "noBackground",
35
- "noBorder",
36
- "noPadding",
37
- "noGap",
38
- "noRadius",
39
- "noForeground"
40
- ];
41
- export function semanticProps(attributes, contract, defaults = DEFAULT_SEMANTIC_PROPS) {
42
- const input = Object.fromEntries(SEMANTIC_KEYS
43
- .filter((key) => attributes[key] !== undefined)
44
- .map((key) => [key, attributes[key]]));
45
- return contract
46
- ? resolveDynamicStyleflowProps(input, defaults, contract)
47
- : { ...defaults, ...input };
48
- }
49
- export function objectValue(block, key) {
50
- const value = block.attributes[key];
51
- return value && typeof value === "object" && !Array.isArray(value)
52
- ? value
53
- : {};
54
- }
55
- export function textValue(block, key = "text") {
56
- return String(block.attributes[key] ?? "");
57
- }
58
- /**
59
- * Keep intentional blank lines visible across current and legacy RichText
60
- * serializations. Gutenberg can represent them either as repeated `<br>` tags,
61
- * empty paragraph elements, or literal newlines in an attribute value.
62
- */
63
- export function preserveRichTextSpacing(html) {
64
- const visibleEmptyBlocks = html
65
- .replace(/\r\n?/g, "\n")
66
- .replace(/<(p|div)(\s[^>]*)?>(?:\s|&nbsp;|&#160;)*<\/\1>/gi, (_match, tag, attributes = "") => `<${tag}${attributes}>&nbsp;</${tag}>`);
67
- return visibleEmptyBlocks
68
- .split(/(<[^>]+>)/g)
69
- .map((part) => {
70
- if (part.startsWith("<") || part.trim() === "") {
71
- return part;
72
- }
73
- return part.replace(/\n(?:[ \t]*\n)+/g, (newlines) => "<br>".repeat((newlines.match(/\n/g) || []).length));
74
- })
75
- .join("");
76
- }
77
- /** Keep an empty text element at its typographic line height without visible text. */
78
- export function preserveEmptyTextBlock(html) {
79
- return html.trim() === "" ? "&nbsp;" : html;
80
- }
81
- export function linkValue(block, key = "link") {
82
- const value = block.attributes[key];
83
- const href = typeof value === "string"
84
- ? value
85
- : String(objectValue(block, key).url ?? "");
86
- return /^(?:\/(?!\/)|#|https?:\/\/|mailto:|tel:)/i.test(href) ? href : "";
87
- }
88
- export function responsiveValues(attributes, prefix, fallback) {
89
- const keys = ["base", "sm", "md", "lg", "xl", "2xl"];
90
- const result = {};
91
- let inherited = fallback;
92
- for (const key of keys) {
93
- const suffix = key === "base"
94
- ? "Base"
95
- : key === "2xl" ? "2xl" : key.charAt(0).toUpperCase() + key.slice(1);
96
- const candidate = Number(attributes[`${prefix}${suffix}`]);
97
- if (Number.isInteger(candidate) && candidate >= 1 && candidate <= 12) {
98
- inherited = candidate;
99
- }
100
- result[key] = inherited;
101
- }
102
- return result;
103
- }
104
- export function unwrapCoreHtml(html) {
105
- const match = html.trim().match(/^<(p|h[1-6]|ul|ol|li|blockquote)(?:\s[^>]*)?>([\s\S]*)<\/\1>$/);
106
- return match?.[2] ?? html;
107
- }
108
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/astro/blocks/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,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,QAAQ,CAAC;IACzB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM;YAC3B,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvE,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;QAC3D,IAAI,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI,SAAS,IAAI,EAAE,EAAE,CAAC;YACrE,SAAS,GAAG,SAAS,CAAC;QACxB,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC1B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAC7B,+DAA+D,CAChE,CAAC;IACF,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC5B,CAAC","sourcesContent":["import {\n resolveDynamicStyleflowProps,\n type StyleflowContract\n} from \"../../styleflow.js\";\nimport type { FlowpressBlock } from \"../../types.js\";\n\nexport const DEFAULT_SEMANTIC_PROPS = {\n surface: \"default\",\n layoutRole: \"stack\",\n density: \"md\"\n};\n\nexport function blockHtmlAttributes(\n attributes: Record<string, unknown>,\n baseClass = \"\"\n): { id?: string; class?: string } {\n const anchor = typeof attributes.anchor === \"string\"\n ? attributes.anchor.trim()\n : \"\";\n const customClass = typeof attributes.className === \"string\"\n ? attributes.className.trim()\n : \"\";\n const className = [baseClass.trim(), customClass]\n .filter(Boolean)\n .join(\" \")\n .replace(/\\s+/g, \" \");\n\n return {\n ...(anchor ? { id: anchor } : {}),\n ...(className ? { class: className } : {})\n };\n}\n\nconst SEMANTIC_KEYS = [\n \"tone\",\n \"intensity\",\n \"surface\",\n \"layoutRole\",\n \"density\",\n \"ty\",\n \"v\",\n \"w\",\n \"foreground\",\n \"interactivePriority\",\n \"noBackground\",\n \"noBorder\",\n \"noPadding\",\n \"noGap\",\n \"noRadius\",\n \"noForeground\"\n] as const;\n\nexport function semanticProps(\n attributes: Record<string, unknown>,\n contract?: StyleflowContract,\n defaults: Record<string, unknown> = DEFAULT_SEMANTIC_PROPS\n): Record<string, unknown> {\n const input = Object.fromEntries(\n SEMANTIC_KEYS\n .filter((key) => attributes[key] !== undefined)\n .map((key) => [key, attributes[key]])\n );\n return contract\n ? resolveDynamicStyleflowProps(input, defaults, contract)\n : { ...defaults, ...input };\n}\n\nexport function objectValue(\n block: FlowpressBlock,\n key: string\n): Record<string, unknown> {\n const value = block.attributes[key];\n return value && typeof value === \"object\" && !Array.isArray(value)\n ? value as Record<string, unknown>\n : {};\n}\n\nexport function textValue(block: FlowpressBlock, key = \"text\"): string {\n return String(block.attributes[key] ?? \"\");\n}\n\n/**\n * Keep intentional blank lines visible across current and legacy RichText\n * serializations. Gutenberg can represent them either as repeated `<br>` tags,\n * empty paragraph elements, or literal newlines in an attribute value.\n */\nexport function preserveRichTextSpacing(html: string): string {\n const visibleEmptyBlocks = html\n .replace(/\\r\\n?/g, \"\\n\")\n .replace(\n /<(p|div)(\\s[^>]*)?>(?:\\s|&nbsp;|&#160;)*<\\/\\1>/gi,\n (_match, tag: string, attributes = \"\") =>\n `<${tag}${attributes}>&nbsp;</${tag}>`\n );\n\n return visibleEmptyBlocks\n .split(/(<[^>]+>)/g)\n .map((part) => {\n if (part.startsWith(\"<\") || part.trim() === \"\") {\n return part;\n }\n return part.replace(/\\n(?:[ \\t]*\\n)+/g, (newlines) =>\n \"<br>\".repeat((newlines.match(/\\n/g) || []).length)\n );\n })\n .join(\"\");\n}\n\n/** Keep an empty text element at its typographic line height without visible text. */\nexport function preserveEmptyTextBlock(html: string): string {\n return html.trim() === \"\" ? \"&nbsp;\" : html;\n}\n\nexport function linkValue(block: FlowpressBlock, key = \"link\"): string {\n const value = block.attributes[key];\n const href = typeof value === \"string\"\n ? value\n : String(objectValue(block, key).url ?? \"\");\n return /^(?:\\/(?!\\/)|#|https?:\\/\\/|mailto:|tel:)/i.test(href) ? href : \"\";\n}\n\nexport function responsiveValues(\n attributes: Record<string, unknown>,\n prefix: \"columns\" | \"span\",\n fallback: number\n): Record<\"base\" | \"sm\" | \"md\" | \"lg\" | \"xl\" | \"2xl\", number> {\n const keys = [\"base\", \"sm\", \"md\", \"lg\", \"xl\", \"2xl\"] as const;\n const result = {} as Record<(typeof keys)[number], number>;\n let inherited = fallback;\n for (const key of keys) {\n const suffix = key === \"base\"\n ? \"Base\"\n : key === \"2xl\" ? \"2xl\" : key.charAt(0).toUpperCase() + key.slice(1);\n const candidate = Number(attributes[`${prefix}${suffix}`]);\n if (Number.isInteger(candidate) && candidate >= 1 && candidate <= 12) {\n inherited = candidate;\n }\n result[key] = inherited;\n }\n return result;\n}\n\nexport function unwrapCoreHtml(html: string): string {\n const match = html.trim().match(\n /^<(p|h[1-6]|ul|ol|li|blockquote)(?:\\s[^>]*)?>([\\s\\S]*)<\\/\\1>$/\n );\n return match?.[2] ?? html;\n}\n"]}
@@ -1,148 +0,0 @@
1
- import {
2
- resolveDynamicStyleflowProps,
3
- type StyleflowContract
4
- } from "../../styleflow.js";
5
- import type { FlowpressBlock } from "../../types.js";
6
-
7
- export const DEFAULT_SEMANTIC_PROPS = {
8
- surface: "default",
9
- layoutRole: "stack",
10
- density: "md"
11
- };
12
-
13
- export function blockHtmlAttributes(
14
- attributes: Record<string, unknown>,
15
- baseClass = ""
16
- ): { id?: string; class?: string } {
17
- const anchor = typeof attributes.anchor === "string"
18
- ? attributes.anchor.trim()
19
- : "";
20
- const customClass = typeof attributes.className === "string"
21
- ? attributes.className.trim()
22
- : "";
23
- const className = [baseClass.trim(), customClass]
24
- .filter(Boolean)
25
- .join(" ")
26
- .replace(/\s+/g, " ");
27
-
28
- return {
29
- ...(anchor ? { id: anchor } : {}),
30
- ...(className ? { class: className } : {})
31
- };
32
- }
33
-
34
- const SEMANTIC_KEYS = [
35
- "tone",
36
- "intensity",
37
- "surface",
38
- "layoutRole",
39
- "density",
40
- "ty",
41
- "v",
42
- "w",
43
- "foreground",
44
- "interactivePriority",
45
- "noBackground",
46
- "noBorder",
47
- "noPadding",
48
- "noGap",
49
- "noRadius",
50
- "noForeground"
51
- ] as const;
52
-
53
- export function semanticProps(
54
- attributes: Record<string, unknown>,
55
- contract?: StyleflowContract,
56
- defaults: Record<string, unknown> = DEFAULT_SEMANTIC_PROPS
57
- ): Record<string, unknown> {
58
- const input = Object.fromEntries(
59
- SEMANTIC_KEYS
60
- .filter((key) => attributes[key] !== undefined)
61
- .map((key) => [key, attributes[key]])
62
- );
63
- return contract
64
- ? resolveDynamicStyleflowProps(input, defaults, contract)
65
- : { ...defaults, ...input };
66
- }
67
-
68
- export function objectValue(
69
- block: FlowpressBlock,
70
- key: string
71
- ): Record<string, unknown> {
72
- const value = block.attributes[key];
73
- return value && typeof value === "object" && !Array.isArray(value)
74
- ? value as Record<string, unknown>
75
- : {};
76
- }
77
-
78
- export function textValue(block: FlowpressBlock, key = "text"): string {
79
- return String(block.attributes[key] ?? "");
80
- }
81
-
82
- /**
83
- * Keep intentional blank lines visible across current and legacy RichText
84
- * serializations. Gutenberg can represent them either as repeated `<br>` tags,
85
- * empty paragraph elements, or literal newlines in an attribute value.
86
- */
87
- export function preserveRichTextSpacing(html: string): string {
88
- const visibleEmptyBlocks = html
89
- .replace(/\r\n?/g, "\n")
90
- .replace(
91
- /<(p|div)(\s[^>]*)?>(?:\s|&nbsp;|&#160;)*<\/\1>/gi,
92
- (_match, tag: string, attributes = "") =>
93
- `<${tag}${attributes}>&nbsp;</${tag}>`
94
- );
95
-
96
- return visibleEmptyBlocks
97
- .split(/(<[^>]+>)/g)
98
- .map((part) => {
99
- if (part.startsWith("<") || part.trim() === "") {
100
- return part;
101
- }
102
- return part.replace(/\n(?:[ \t]*\n)+/g, (newlines) =>
103
- "<br>".repeat((newlines.match(/\n/g) || []).length)
104
- );
105
- })
106
- .join("");
107
- }
108
-
109
- /** Keep an empty text element at its typographic line height without visible text. */
110
- export function preserveEmptyTextBlock(html: string): string {
111
- return html.trim() === "" ? "&nbsp;" : html;
112
- }
113
-
114
- export function linkValue(block: FlowpressBlock, key = "link"): string {
115
- const value = block.attributes[key];
116
- const href = typeof value === "string"
117
- ? value
118
- : String(objectValue(block, key).url ?? "");
119
- return /^(?:\/(?!\/)|#|https?:\/\/|mailto:|tel:)/i.test(href) ? href : "";
120
- }
121
-
122
- export function responsiveValues(
123
- attributes: Record<string, unknown>,
124
- prefix: "columns" | "span",
125
- fallback: number
126
- ): Record<"base" | "sm" | "md" | "lg" | "xl" | "2xl", number> {
127
- const keys = ["base", "sm", "md", "lg", "xl", "2xl"] as const;
128
- const result = {} as Record<(typeof keys)[number], number>;
129
- let inherited = fallback;
130
- for (const key of keys) {
131
- const suffix = key === "base"
132
- ? "Base"
133
- : key === "2xl" ? "2xl" : key.charAt(0).toUpperCase() + key.slice(1);
134
- const candidate = Number(attributes[`${prefix}${suffix}`]);
135
- if (Number.isInteger(candidate) && candidate >= 1 && candidate <= 12) {
136
- inherited = candidate;
137
- }
138
- result[key] = inherited;
139
- }
140
- return result;
141
- }
142
-
143
- export function unwrapCoreHtml(html: string): string {
144
- const match = html.trim().match(
145
- /^<(p|h[1-6]|ul|ol|li|blockquote)(?:\s[^>]*)?>([\s\S]*)<\/\1>$/
146
- );
147
- return match?.[2] ?? html;
148
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Collect class names authored in Gutenberg from serialized FlowPress blocks.
3
- *
4
- * The traversal includes resolved template/list blocks stored inside
5
- * attributes as well as ordinary inner blocks. Tokens that could terminate a
6
- * generated Tailwind `@source inline()` directive are discarded.
7
- */
8
- export declare function collectFlowpressClassNames(blocks: unknown): string[];
9
- //# sourceMappingURL=style-classes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"style-classes.d.ts","sourceRoot":"","sources":["../src/style-classes.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CA8BpE"}
@@ -1,47 +0,0 @@
1
- const MAX_CLASS_LENGTH = 256;
2
- const UNSAFE_CLASS_CHARACTERS = /[\s\\{};\u0000-\u001f\u007f]/;
3
- function classTokens(value) {
4
- if (typeof value !== "string") {
5
- return [];
6
- }
7
- return value
8
- .split(/\s+/)
9
- .map((token) => token.trim())
10
- .filter((token) => (token.length > 0
11
- && token.length <= MAX_CLASS_LENGTH
12
- && !UNSAFE_CLASS_CHARACTERS.test(token)));
13
- }
14
- /**
15
- * Collect class names authored in Gutenberg from serialized FlowPress blocks.
16
- *
17
- * The traversal includes resolved template/list blocks stored inside
18
- * attributes as well as ordinary inner blocks. Tokens that could terminate a
19
- * generated Tailwind `@source inline()` directive are discarded.
20
- */
21
- export function collectFlowpressClassNames(blocks) {
22
- const classes = new Set();
23
- const visited = new WeakSet();
24
- const visit = (value) => {
25
- if (!value || typeof value !== "object") {
26
- return;
27
- }
28
- if (visited.has(value)) {
29
- return;
30
- }
31
- visited.add(value);
32
- if (Array.isArray(value)) {
33
- value.forEach(visit);
34
- return;
35
- }
36
- const block = value;
37
- if (block.attributes && typeof block.attributes === "object") {
38
- for (const token of classTokens(block.attributes.className)) {
39
- classes.add(token);
40
- }
41
- }
42
- Object.values(value).forEach(visit);
43
- };
44
- visit(blocks);
45
- return [...classes].sort((left, right) => left.localeCompare(right));
46
- }
47
- //# sourceMappingURL=style-classes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"style-classes.js","sourceRoot":"","sources":["../src/style-classes.ts"],"names":[],"mappings":"AAE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,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC;IAEF,KAAK,CAAC,MAAM,CAAC,CAAC;IACd,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import type { FlowpressBlock } from \"./types.js\";\n\nconst MAX_CLASS_LENGTH = 256;\nconst UNSAFE_CLASS_CHARACTERS = /[\\s\\\\{};\\u0000-\\u001f\\u007f]/;\n\nfunction classTokens(value: unknown): string[] {\n if (typeof value !== \"string\") {\n return [];\n }\n\n return value\n .split(/\\s+/)\n .map((token) => token.trim())\n .filter((token) => (\n token.length > 0\n && token.length <= MAX_CLASS_LENGTH\n && !UNSAFE_CLASS_CHARACTERS.test(token)\n ));\n}\n\n/**\n * Collect class names authored in Gutenberg from serialized FlowPress blocks.\n *\n * The traversal includes resolved template/list blocks stored inside\n * attributes as well as ordinary inner blocks. Tokens that could terminate a\n * generated Tailwind `@source inline()` directive are discarded.\n */\nexport function collectFlowpressClassNames(blocks: unknown): string[] {\n const classes = new Set<string>();\n const visited = new WeakSet<object>();\n\n const visit = (value: unknown): void => {\n if (!value || typeof value !== \"object\") {\n return;\n }\n if (visited.has(value)) {\n return;\n }\n visited.add(value);\n\n if (Array.isArray(value)) {\n value.forEach(visit);\n return;\n }\n\n const block = value as Partial<FlowpressBlock>;\n if (block.attributes && typeof block.attributes === \"object\") {\n for (const token of classTokens(block.attributes.className)) {\n classes.add(token);\n }\n }\n\n Object.values(value).forEach(visit);\n };\n\n visit(blocks);\n return [...classes].sort((left, right) => left.localeCompare(right));\n}\n"]}