@onderwijsin/nuxt-loops-renderer 0.2.10 → 0.3.0
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/README.md +154 -14
- package/dist/module.d.mts +9 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +18 -2
- package/dist/runtime/app/components/LoopsRenderer.vue +2 -0
- package/dist/runtime/app/components/nodes/LoopsAstCodeBlock.vue +8 -7
- package/dist/runtime/app/components/nodes/LoopsAstComponent.vue +8 -5
- package/dist/runtime/app/components/nodes/LoopsAstIcons.vue +7 -3
- package/dist/runtime/app/components/nodes/LoopsAstInline.vue +5 -7
- package/dist/runtime/app/components/nodes/LoopsAstLayout.vue +8 -7
- package/dist/runtime/app/components/nodes/LoopsAstList.vue +12 -19
- package/dist/runtime/app/components/nodes/LoopsAstListItem.d.vue.ts +10 -0
- package/dist/runtime/app/components/nodes/LoopsAstListItem.vue +25 -0
- package/dist/runtime/app/components/nodes/LoopsAstListItem.vue.d.ts +10 -0
- package/dist/runtime/app/components/nodes/LoopsAstMedia.vue +9 -21
- package/dist/runtime/app/components/nodes/LoopsAstNode.vue +8 -4
- package/dist/runtime/app/components/nodes/LoopsAstSection.vue +7 -6
- package/dist/runtime/app/components/nodes/LoopsAstTextBlock.vue +7 -9
- package/dist/runtime/app/composables/node-styles.d.ts +13 -0
- package/dist/runtime/app/composables/node-styles.js +22 -0
- package/dist/runtime/app/utils/color-map.d.ts +15 -0
- package/dist/runtime/app/utils/color-map.js +22 -0
- package/dist/runtime/app/utils/color-mapper-approximation.d.ts +8 -0
- package/dist/runtime/app/utils/color-mapper-approximation.js +33 -0
- package/dist/runtime/app/utils/color-mapper.d.ts +8 -0
- package/dist/runtime/app/utils/color-mapper.js +8 -0
- package/dist/runtime/app/utils/oklab.d.ts +20 -0
- package/dist/runtime/app/utils/oklab.js +20 -0
- package/dist/runtime/app/utils/styles.d.ts +14 -0
- package/dist/runtime/app/utils/styles.js +29 -0
- package/dist/runtime/index.css +1 -1
- package/dist/runtime/types.d.ts +41 -3
- package/dist/types.d.mts +2 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -15,9 +15,12 @@ omits invalid or unsupported content.
|
|
|
15
15
|
Install the module:
|
|
16
16
|
|
|
17
17
|
```sh
|
|
18
|
-
pnpm add @onderwijsin/nuxt-loops-renderer @onderwijsin/loops-core
|
|
18
|
+
pnpm add @onderwijsin/nuxt-loops-renderer @nuxt/ui @onderwijsin/loops-core
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
The application supplies `@nuxt/ui` as a peer dependency so module runtime code shares the
|
|
22
|
+
application's instances. Nuxt module registration remains automatic.
|
|
23
|
+
|
|
21
24
|
Register it in `nuxt.config.ts`:
|
|
22
25
|
|
|
23
26
|
```ts
|
|
@@ -70,11 +73,11 @@ const parsedAst = await getParsedCampaignAst();
|
|
|
70
73
|
|
|
71
74
|
The component accepts the following props:
|
|
72
75
|
|
|
73
|
-
| Prop | Required | Description
|
|
74
|
-
| ----------- | -------- |
|
|
75
|
-
| `data` | Yes | A `LoopsLmxAst` root returned by `@onderwijsin/loops-core`.
|
|
76
|
-
| `variables` | Yes | Values available to `{contact.*}`, `{event.*}`, and `{data.*}` merge tags.
|
|
77
|
-
| `config` | No | Per-renderer overrides for debugging,
|
|
76
|
+
| Prop | Required | Description |
|
|
77
|
+
| ----------- | -------- | ----------------------------------------------------------------------------------- |
|
|
78
|
+
| `data` | Yes | A `LoopsLmxAst` root returned by `@onderwijsin/loops-core`. |
|
|
79
|
+
| `variables` | Yes | Values available to `{contact.*}`, `{event.*}`, and `{data.*}` merge tags. |
|
|
80
|
+
| `config` | No | Per-renderer overrides for debugging, styles, color mapping, themes and evaluation. |
|
|
78
81
|
|
|
79
82
|
```vue
|
|
80
83
|
<LoopsRenderer :data="parsedAst" :variables="variables" :config="{ applyInlineStyles: false }" />
|
|
@@ -116,20 +119,157 @@ export default defineNuxtConfig({
|
|
|
116
119
|
|
|
117
120
|
Available module options are:
|
|
118
121
|
|
|
119
|
-
| Option
|
|
120
|
-
|
|
|
121
|
-
| `enabled`
|
|
122
|
-
| `applyInlineStyles`
|
|
123
|
-
| `
|
|
122
|
+
| Option | Default | Description |
|
|
123
|
+
| ---------------------------- | --------- | ------------------------------------------------------------------------- |
|
|
124
|
+
| `enabled` | `true` | Set to `false` to skip runtime registration and module dependencies. |
|
|
125
|
+
| `applyInlineStyles` | `true` | Apply validated LMX presentation attributes as inline styles. |
|
|
126
|
+
| `sourceTheme` | Unset | Authored AST theme: `"light"` or `"dark"`. Unset means unknown. |
|
|
127
|
+
| `colorMapping.approximation` | `false` | Select nearest-source fallback in `createLoopsColorMapper` at build time. |
|
|
128
|
+
| `evaluate` | See above | Fallbacks for missing variables and invalid conditional rules. |
|
|
124
129
|
|
|
125
|
-
The same `applyInlineStyles` and `evaluate` options can be overridden for an
|
|
126
|
-
`LoopsRenderer` with its `config` prop. `debug` is a per-renderer option and is intended
|
|
127
|
-
development diagnostics.
|
|
130
|
+
The same `applyInlineStyles`, `sourceTheme` and `evaluate` options can be overridden for an
|
|
131
|
+
individual `LoopsRenderer` with its `config` prop. `debug` is a per-renderer option and is intended
|
|
132
|
+
for development diagnostics.
|
|
128
133
|
|
|
129
134
|
Conditional sections use LMX attributes such as `if`, `ifOperation`, and `ifValue`. Evaluation never
|
|
130
135
|
throws; missing variables and invalid conditions use the configured fallbacks, which default to
|
|
131
136
|
`false`.
|
|
132
137
|
|
|
138
|
+
## Runtime color mapping
|
|
139
|
+
|
|
140
|
+
The renderer applies mappings; your application owns the mapping policy. Pass a synchronous
|
|
141
|
+
`config.mapColor(color, context)` callback to map exact source colors to your palette or CSS tokens.
|
|
142
|
+
Returning `undefined` preserves the original validated value. Without a mapper, output is unchanged.
|
|
143
|
+
|
|
144
|
+
Declare the authored theme with `sourceTheme`, either as a module default or per-renderer setting.
|
|
145
|
+
Pass your application's current theme as `config.targetTheme`. Both accept `"light" | "dark"`,
|
|
146
|
+
default to unknown, and are metadata for your callback: the renderer does not infer themes or skip
|
|
147
|
+
mapping automatically when they match. The AST and its ingestion/storage format stay unchanged.
|
|
148
|
+
|
|
149
|
+
For example, this wrapper supplies a 1:1 light-to-dark lookup with CSS-variable output:
|
|
150
|
+
|
|
151
|
+
```vue
|
|
152
|
+
<script setup lang="ts">
|
|
153
|
+
import { computed } from "vue";
|
|
154
|
+
import type { LoopsLmxAst, LoopsLmxVariables } from "@onderwijsin/loops-core";
|
|
155
|
+
import type {
|
|
156
|
+
LoopsRendererColorProperty,
|
|
157
|
+
LoopsRendererConfig,
|
|
158
|
+
LoopsRendererTheme
|
|
159
|
+
} from "@onderwijsin/nuxt-loops-renderer";
|
|
160
|
+
|
|
161
|
+
defineProps<{ data: LoopsLmxAst; variables: LoopsLmxVariables }>();
|
|
162
|
+
const targetTheme = useState<LoopsRendererTheme>("campaign-theme", () => "light");
|
|
163
|
+
const darkColors: Partial<Record<LoopsRendererColorProperty, Record<string, string>>> = {
|
|
164
|
+
color: { "#111111": "var(--campaign-text)", "#ffffff": "#111111" },
|
|
165
|
+
backgroundColor: { "#ffffff": "var(--campaign-surface)", "#111111": "#eeeeee" },
|
|
166
|
+
borderColor: { "#cccccc": "var(--campaign-border)" }
|
|
167
|
+
};
|
|
168
|
+
const paletteMapper = createLoopsColorMapper(darkColors);
|
|
169
|
+
const config = computed<LoopsRendererConfig>(() => ({
|
|
170
|
+
sourceTheme: "light",
|
|
171
|
+
targetTheme: targetTheme.value,
|
|
172
|
+
mapColor: (color, context) =>
|
|
173
|
+
context.sourceTheme === "light" && context.targetTheme === "dark"
|
|
174
|
+
? paletteMapper(color, context)
|
|
175
|
+
: undefined
|
|
176
|
+
}));
|
|
177
|
+
</script>
|
|
178
|
+
|
|
179
|
+
<template>
|
|
180
|
+
<button @click="targetTheme = targetTheme === 'light' ? 'dark' : 'light'">Switch theme</button>
|
|
181
|
+
<LoopsRenderer :data="data" :variables="variables" :config="config" />
|
|
182
|
+
</template>
|
|
183
|
+
|
|
184
|
+
<style>
|
|
185
|
+
:root {
|
|
186
|
+
--campaign-text: #eeeeee;
|
|
187
|
+
--campaign-surface: #18181b;
|
|
188
|
+
--campaign-border: #52525b;
|
|
189
|
+
}
|
|
190
|
+
</style>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
For an AST authored in dark mode, set `sourceTheme: "dark"` and supply your own dark-to-light
|
|
194
|
+
lookup. Matching and normalization belong to your policy; source hex values retain their authored
|
|
195
|
+
case and length in custom callbacks. The optional palette utility below normalizes these values.
|
|
196
|
+
|
|
197
|
+
### Exact-first palette utility
|
|
198
|
+
|
|
199
|
+
`createLoopsColorMapper(mappings, options?)` is auto-imported by the module. It returns a callback
|
|
200
|
+
for `config.mapColor`. Palettes are separated by `color`, `backgroundColor` and `borderColor`;
|
|
201
|
+
targets are trusted CSS colors or variable references. Source keys accept only three- or six-digit
|
|
202
|
+
hex and are normalized to lowercase six-digit hex, so `#FFF` matches `#ffffff`. Invalid source keys
|
|
203
|
+
and duplicate normalized keys throw `TypeError` when the mapper is created.
|
|
204
|
+
|
|
205
|
+
By default the utility performs exact matches only. Enable approximation in `nuxt.config.ts`:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
export default defineNuxtConfig({
|
|
209
|
+
modules: ["@onderwijsin/nuxt-loops-renderer"],
|
|
210
|
+
loopsRenderer: { colorMapping: { approximation: true } }
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Then use the same utility in application code:
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
const mapColor = createLoopsColorMapper(
|
|
218
|
+
{
|
|
219
|
+
color: { "#111111": "var(--campaign-text)" },
|
|
220
|
+
backgroundColor: { "#ffffff": "var(--campaign-surface)" }
|
|
221
|
+
},
|
|
222
|
+
{ maxDeltaE: 0.03 }
|
|
223
|
+
);
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Pass it through `config.mapColor`, or call it inside a custom callback that selects the correct
|
|
227
|
+
palette for the source and target themes. The utility itself does not infer theme direction or skip
|
|
228
|
+
equal themes. A mapper snapshots its palette at creation; recreate it when mappings change.
|
|
229
|
+
|
|
230
|
+
The enabled strategy always tries exact matching first, then searches the same role's **source**
|
|
231
|
+
colors using Euclidean OKLab distance. It reuses the nearest source's mapped value without
|
|
232
|
+
interpreting target CSS variables. `maxDeltaE` defaults to `0.03`, must be finite and non-negative,
|
|
233
|
+
and is inclusive. Set it to `0` for exact-only matching in an approximation-enabled build. It has no
|
|
234
|
+
effect in an exact-only build. Equal-distance ties use canonical source-hex order. An empty role or
|
|
235
|
+
an out-of-range color returns `undefined`, preserving the original value.
|
|
236
|
+
|
|
237
|
+
Nuxt selects the utility implementation at build time. Disabled approximation has no OKLab strategy
|
|
238
|
+
or distance mathematics in the generated client or server bundles. An unused utility is not bundled,
|
|
239
|
+
even if approximation is enabled. The renderer's small callback/context integration remains
|
|
240
|
+
available for handwritten mappers. These module options cannot be enabled per renderer at runtime.
|
|
241
|
+
|
|
242
|
+
The exported `LoopsRendererColorMapper` receives the original validated hex plus a typed
|
|
243
|
+
`LoopsRendererColorContext`:
|
|
244
|
+
|
|
245
|
+
| Context field | Meaning |
|
|
246
|
+
| ---------------------------- | --------------------------------------------------------------------------------------- |
|
|
247
|
+
| `property` | `color`, `backgroundColor` or `borderColor`; distinguishes text, surfaces and borders. |
|
|
248
|
+
| `nodeType`, `nodeName` | The source element type (`"element"`) and LMX name, such as `Button` or `Text`. |
|
|
249
|
+
| `colors` | Readonly snapshot of this node's explicit validated color declarations, before mapping. |
|
|
250
|
+
| `backgroundColor` | This node's explicit background, otherwise the nearest authored ancestor background. |
|
|
251
|
+
| `parentBackgroundColor` | Nearest authored ancestor background before this node's own background. |
|
|
252
|
+
| `sourceTheme`, `targetTheme` | Consumer-supplied themes, or `undefined` when unknown. |
|
|
253
|
+
|
|
254
|
+
All context colors are unmapped source values. Foreground/background pairs on buttons and nested
|
|
255
|
+
backgrounds are available to your policy, including explicit inline text overrides. Host CSS,
|
|
256
|
+
computed styles, inherited host foregrounds, and Loops theme/`Style` defaults are unknown; a mapper
|
|
257
|
+
does not guarantee contrast. Only declarations already supported by core style validation are
|
|
258
|
+
mapped, including core's existing interpretation of `color` as `borderColor` on dividers/icons.
|
|
259
|
+
|
|
260
|
+
Callback results are trusted application CSS color values, including `var(...)` references. Do not
|
|
261
|
+
return untrusted strings. Persisted AST values still pass core validation before mapping; CSS
|
|
262
|
+
variables in persisted color attributes are rejected. Non-color styles and asset URLs are preserved,
|
|
263
|
+
and image pixels are never recolored. `applyInlineStyles: false` skips source styles and mapping.
|
|
264
|
+
|
|
265
|
+
Keep callbacks pure and deterministic for the same inputs on server and client. Pass them via the
|
|
266
|
+
runtime component `config` prop; do not serialize them through `nuxt.config.ts` or runtime config.
|
|
267
|
+
Reactive config or reactive values read by the callback update styles without reparsing the AST. Use
|
|
268
|
+
SSR-consistent initial theme state (as above), or stable CSS-variable output whose definitions
|
|
269
|
+
follow your application's theme, to avoid hydration mismatches. There is no module-owned OS-theme
|
|
270
|
+
detector. Automatic theme conversion is not provided; approximation only reuses consumer-supplied
|
|
271
|
+
mapping values. No color-library dependency is required.
|
|
272
|
+
|
|
133
273
|
## Relationship with `@onderwijsin/loops-core`
|
|
134
274
|
|
|
135
275
|
`@onderwijsin/loops-core` is the framework-agnostic foundation. It parses LMX into a
|
package/dist/module.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
export { LoopsRendererColorContext, LoopsRendererColorMap, LoopsRendererColorMapper, LoopsRendererColorMappingOptions, LoopsRendererColorProperty, LoopsRendererColors, LoopsRendererConfig, LoopsRendererTheme } from '../dist/runtime/types.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Provides the Nuxt runtime foundation for rendering Loops LMX email content.
|
|
@@ -6,6 +7,10 @@ import * as _nuxt_schema from '@nuxt/schema';
|
|
|
6
7
|
declare const _default: _nuxt_schema.NuxtModule<{
|
|
7
8
|
enabled?: boolean | undefined;
|
|
8
9
|
applyInlineStyles?: boolean | undefined;
|
|
10
|
+
sourceTheme?: "light" | "dark" | undefined;
|
|
11
|
+
colorMapping?: {
|
|
12
|
+
approximation?: boolean | undefined;
|
|
13
|
+
} | undefined;
|
|
9
14
|
evaluate?: {
|
|
10
15
|
onMissingVariable?: boolean | undefined;
|
|
11
16
|
onInvalidCondition?: boolean | undefined;
|
|
@@ -14,6 +19,10 @@ declare const _default: _nuxt_schema.NuxtModule<{
|
|
|
14
19
|
}, {
|
|
15
20
|
enabled?: boolean | undefined;
|
|
16
21
|
applyInlineStyles?: boolean | undefined;
|
|
22
|
+
sourceTheme?: "light" | "dark" | undefined;
|
|
23
|
+
colorMapping?: {
|
|
24
|
+
approximation?: boolean | undefined;
|
|
25
|
+
} | undefined;
|
|
17
26
|
evaluate?: {
|
|
18
27
|
onMissingVariable?: boolean | undefined;
|
|
19
28
|
onInvalidCondition?: boolean | undefined;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { defineNuxtModule, useLogger, createResolver, addComponentsDir } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, useLogger, createResolver, addImports, addComponentsDir } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
import { enabled, resolveModuleName, resolveLoggerScope, moduleSetup, transpileRuntime, moduleDependenciesWhenEnabled } from '@onderwijsin/nuxt-module-utils/build';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
|
-
const version = "0.
|
|
6
|
+
const version = "0.3.0";
|
|
7
7
|
|
|
8
8
|
const EVALUATE_DEFAULTS = {
|
|
9
9
|
onMissingVariable: false,
|
|
@@ -13,6 +13,12 @@ const EVALUATE_DEFAULTS = {
|
|
|
13
13
|
const loopsRendererOptionsSchema = z.strictObject({
|
|
14
14
|
enabled,
|
|
15
15
|
applyInlineStyles: z.boolean().default(true),
|
|
16
|
+
/** Theme in which archived colors were authored; omitted means unknown. */
|
|
17
|
+
sourceTheme: z.enum(["light", "dark"]).optional(),
|
|
18
|
+
colorMapping: z.strictObject({
|
|
19
|
+
/** Include the nearest-source-color strategy in the auto-imported mapper utility. */
|
|
20
|
+
approximation: z.boolean().default(false)
|
|
21
|
+
}).default({ approximation: false }),
|
|
16
22
|
evaluate: z.strictObject({
|
|
17
23
|
/** Result for a valid variable whose value is null or undefined. */
|
|
18
24
|
onMissingVariable: z.boolean().default(EVALUATE_DEFAULTS.onMissingVariable),
|
|
@@ -53,6 +59,7 @@ const module$1 = defineNuxtModule({
|
|
|
53
59
|
nuxt.options.appConfig.loopsRenderer = defu(
|
|
54
60
|
{
|
|
55
61
|
applyInlineStyles: validatedOptions.applyInlineStyles,
|
|
62
|
+
sourceTheme: validatedOptions.sourceTheme,
|
|
56
63
|
evaluate: validatedOptions.evaluate
|
|
57
64
|
},
|
|
58
65
|
nuxt.options.appConfig.loopsRenderer
|
|
@@ -60,6 +67,15 @@ const module$1 = defineNuxtModule({
|
|
|
60
67
|
const resolver = createResolver(import.meta.url);
|
|
61
68
|
const runtimeDir = resolver.resolve("./runtime");
|
|
62
69
|
transpileRuntime(nuxt, runtimeDir);
|
|
70
|
+
addImports({
|
|
71
|
+
name: "createLoopsColorMapper",
|
|
72
|
+
from: resolver.resolve(
|
|
73
|
+
runtimeDir,
|
|
74
|
+
"app",
|
|
75
|
+
"utils",
|
|
76
|
+
validatedOptions.colorMapping.approximation ? "color-mapper-approximation" : "color-mapper"
|
|
77
|
+
)
|
|
78
|
+
});
|
|
63
79
|
addComponentsDir({
|
|
64
80
|
path: resolver.resolve(runtimeDir, "app", "components"),
|
|
65
81
|
pathPrefix: false
|
|
@@ -6,12 +6,14 @@ import {
|
|
|
6
6
|
hasRenderableLoopsLmxNodes,
|
|
7
7
|
hasUnsupportedLoopsLmxNodes
|
|
8
8
|
} from "@onderwijsin/loops-core";
|
|
9
|
+
import { resetLoopsRendererBackground } from "../composables/node-styles";
|
|
9
10
|
import { createLoopsRendererConfig } from "../utils/renderer";
|
|
10
11
|
const props = defineProps({
|
|
11
12
|
data: { type: Object, required: true },
|
|
12
13
|
variables: { type: Object, required: true },
|
|
13
14
|
config: { type: Object, required: false }
|
|
14
15
|
});
|
|
16
|
+
resetLoopsRendererBackground();
|
|
15
17
|
const appConfig = useAppConfig();
|
|
16
18
|
const rendererConfig = computed(
|
|
17
19
|
() => createLoopsRendererConfig(props.config, appConfig.loopsRenderer)
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
defineProps({
|
|
2
|
+
import {} from "@onderwijsin/loops-core";
|
|
3
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
4
|
+
const props = defineProps({
|
|
6
5
|
node: { type: Object, required: true },
|
|
7
6
|
variables: { type: Object, required: true },
|
|
8
7
|
config: { type: Object, required: true }
|
|
9
8
|
});
|
|
9
|
+
const style = useLoopsNodeStyles(
|
|
10
|
+
() => props.node,
|
|
11
|
+
() => props.config
|
|
12
|
+
);
|
|
10
13
|
</script>
|
|
11
14
|
|
|
12
15
|
<template>
|
|
13
|
-
<pre
|
|
14
|
-
:style="applyInlineStyles(node.attributes, config.applyInlineStyles !== false)"
|
|
15
|
-
><code><LoopsAstInline
|
|
16
|
+
<pre :style="style"><code><LoopsAstInline
|
|
16
17
|
v-for="(child, index) in node.children"
|
|
17
18
|
:key="index"
|
|
18
19
|
:node="child"
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
defineProps({
|
|
2
|
+
import {} from "@onderwijsin/loops-core";
|
|
3
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
4
|
+
const props = defineProps({
|
|
6
5
|
node: { type: Object, required: true },
|
|
7
6
|
variables: { type: Object, required: true },
|
|
8
7
|
config: { type: Object, required: true }
|
|
9
8
|
});
|
|
9
|
+
const style = useLoopsNodeStyles(
|
|
10
|
+
() => props.node,
|
|
11
|
+
() => props.config
|
|
12
|
+
);
|
|
10
13
|
</script>
|
|
11
14
|
|
|
12
15
|
<template>
|
|
13
|
-
<div :style="
|
|
16
|
+
<div :style="style">
|
|
14
17
|
<LoopsAstNode
|
|
15
18
|
v-for="(child, index) in node.children"
|
|
16
19
|
:key="index"
|
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
import { computed } from "#imports";
|
|
3
3
|
import {
|
|
4
4
|
getLoopsLmxPixels,
|
|
5
|
-
resolveSafeLoopsLmxUrl
|
|
6
|
-
applyInlineStyles
|
|
5
|
+
resolveSafeLoopsLmxUrl
|
|
7
6
|
} from "@onderwijsin/loops-core";
|
|
7
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
8
8
|
const props = defineProps({
|
|
9
9
|
node: { type: Object, required: true },
|
|
10
10
|
variables: { type: Object, required: true },
|
|
11
11
|
config: { type: Object, required: true }
|
|
12
12
|
});
|
|
13
|
+
const inlineStyle = useLoopsNodeStyles(
|
|
14
|
+
() => props.node,
|
|
15
|
+
() => props.config
|
|
16
|
+
);
|
|
13
17
|
const icons = computed(
|
|
14
18
|
() => (props.node.name === "Icon" ? [props.node] : props.node.children).flatMap((node) => {
|
|
15
19
|
if (node.type !== "element" || node.name !== "Icon") return [];
|
|
@@ -21,7 +25,7 @@ const style = computed(() => ({
|
|
|
21
25
|
display: "flex",
|
|
22
26
|
gap: `${getLoopsLmxPixels(props.node.attributes.gap, 0, 200) ?? 16}px`,
|
|
23
27
|
fontSize: `${getLoopsLmxPixels(props.node.attributes.size, 18, 48) ?? 24}px`,
|
|
24
|
-
...
|
|
28
|
+
...inlineStyle.value
|
|
25
29
|
}));
|
|
26
30
|
function getIconName(name) {
|
|
27
31
|
return {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { computed } from "#imports";
|
|
3
3
|
import {
|
|
4
4
|
resolveSafeLoopsLmxUrl,
|
|
5
|
-
resolveLoopsLmxVariables
|
|
6
|
-
applyInlineStyles
|
|
5
|
+
resolveLoopsLmxVariables
|
|
7
6
|
} from "@onderwijsin/loops-core";
|
|
7
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
8
8
|
const props = defineProps({
|
|
9
9
|
node: { type: Object, required: true },
|
|
10
10
|
variables: { type: Object, required: true },
|
|
@@ -28,11 +28,9 @@ const inlineTag = computed(() => {
|
|
|
28
28
|
Text: "span"
|
|
29
29
|
}[props.node.name];
|
|
30
30
|
});
|
|
31
|
-
const style =
|
|
32
|
-
() =>
|
|
33
|
-
|
|
34
|
-
props.config.applyInlineStyles !== false
|
|
35
|
-
)
|
|
31
|
+
const style = useLoopsNodeStyles(
|
|
32
|
+
() => props.node.type === "element" ? props.node : void 0,
|
|
33
|
+
() => props.config
|
|
36
34
|
);
|
|
37
35
|
</script>
|
|
38
36
|
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed } from "#imports";
|
|
3
3
|
import {
|
|
4
|
-
getLoopsLmxColumnsLayout
|
|
5
|
-
applyInlineStyles
|
|
4
|
+
getLoopsLmxColumnsLayout
|
|
6
5
|
} from "@onderwijsin/loops-core";
|
|
6
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
7
7
|
const props = defineProps({
|
|
8
8
|
node: { type: Object, required: true },
|
|
9
9
|
variables: { type: Object, required: true },
|
|
10
10
|
config: { type: Object, required: true }
|
|
11
11
|
});
|
|
12
|
+
const style = useLoopsNodeStyles(
|
|
13
|
+
() => props.node.name === "Section" ? void 0 : props.node,
|
|
14
|
+
() => props.config
|
|
15
|
+
);
|
|
12
16
|
const columns = computed(
|
|
13
17
|
() => props.node.children.filter(
|
|
14
18
|
(node) => node.type === "element" && node.name === "ColumnItem"
|
|
@@ -34,7 +38,7 @@ const columnsStyle = computed(
|
|
|
34
38
|
v-else-if="node.name === 'Columns' && columns.length"
|
|
35
39
|
:style="{
|
|
36
40
|
...columnsStyle,
|
|
37
|
-
...
|
|
41
|
+
...style
|
|
38
42
|
}"
|
|
39
43
|
>
|
|
40
44
|
<LoopsAstNode
|
|
@@ -45,10 +49,7 @@ const columnsStyle = computed(
|
|
|
45
49
|
:config="config"
|
|
46
50
|
/>
|
|
47
51
|
</div>
|
|
48
|
-
<div
|
|
49
|
-
v-else-if="node.name === 'ColumnItem'"
|
|
50
|
-
:style="applyInlineStyles(node.attributes, config.applyInlineStyles !== false)"
|
|
51
|
-
>
|
|
52
|
+
<div v-else-if="node.name === 'ColumnItem'" :style="style">
|
|
52
53
|
<LoopsAstNode
|
|
53
54
|
v-for="(child, index) in node.children"
|
|
54
55
|
:key="index"
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed } from "#imports";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
} from "@onderwijsin/loops-core";
|
|
3
|
+
import {} from "@onderwijsin/loops-core";
|
|
4
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
6
5
|
const props = defineProps({
|
|
7
6
|
node: { type: Object, required: true },
|
|
8
7
|
variables: { type: Object, required: true },
|
|
9
8
|
config: { type: Object, required: true }
|
|
10
9
|
});
|
|
10
|
+
const style = useLoopsNodeStyles(
|
|
11
|
+
() => props.node,
|
|
12
|
+
() => props.config
|
|
13
|
+
);
|
|
11
14
|
const items = computed(
|
|
12
15
|
() => props.node.children.filter(
|
|
13
16
|
(node) => node.type === "element" && node.name === "ListItem"
|
|
@@ -17,23 +20,13 @@ const tag = computed(() => props.node.name === "OrderedList" ? "ol" : "ul");
|
|
|
17
20
|
</script>
|
|
18
21
|
|
|
19
22
|
<template>
|
|
20
|
-
<component
|
|
21
|
-
|
|
22
|
-
:style="applyInlineStyles(node.attributes, config.applyInlineStyles !== false)"
|
|
23
|
-
>
|
|
24
|
-
<li
|
|
23
|
+
<component :is="tag" :style="style">
|
|
24
|
+
<LoopsAstListItem
|
|
25
25
|
v-for="(item, index) in items"
|
|
26
26
|
:key="index"
|
|
27
|
-
:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
:key="childIndex"
|
|
32
|
-
:node="child"
|
|
33
|
-
:variables="variables"
|
|
34
|
-
:config="config"
|
|
35
|
-
:resolve-variables="true"
|
|
36
|
-
/>
|
|
37
|
-
</li>
|
|
27
|
+
:node="item"
|
|
28
|
+
:variables="variables"
|
|
29
|
+
:config="config"
|
|
30
|
+
/>
|
|
38
31
|
</component>
|
|
39
32
|
</template>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LoopsLmxElement, LoopsLmxVariables } from "@onderwijsin/loops-core";
|
|
2
|
+
import type { LoopsRendererConfig } from "../../../types.js";
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
node: LoopsLmxElement;
|
|
5
|
+
variables: LoopsLmxVariables;
|
|
6
|
+
config: LoopsRendererConfig;
|
|
7
|
+
};
|
|
8
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
3
|
+
const props = defineProps({
|
|
4
|
+
node: { type: Object, required: true },
|
|
5
|
+
variables: { type: Object, required: true },
|
|
6
|
+
config: { type: Object, required: true }
|
|
7
|
+
});
|
|
8
|
+
const style = useLoopsNodeStyles(
|
|
9
|
+
() => props.node,
|
|
10
|
+
() => props.config
|
|
11
|
+
);
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<template>
|
|
15
|
+
<li :style="style">
|
|
16
|
+
<LoopsAstNode
|
|
17
|
+
v-for="(child, index) in node.children"
|
|
18
|
+
:key="index"
|
|
19
|
+
:node="child"
|
|
20
|
+
:variables="variables"
|
|
21
|
+
:config="config"
|
|
22
|
+
:resolve-variables="true"
|
|
23
|
+
/>
|
|
24
|
+
</li>
|
|
25
|
+
</template>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LoopsLmxElement, LoopsLmxVariables } from "@onderwijsin/loops-core";
|
|
2
|
+
import type { LoopsRendererConfig } from "../../../types.js";
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
node: LoopsLmxElement;
|
|
5
|
+
variables: LoopsLmxVariables;
|
|
6
|
+
config: LoopsRendererConfig;
|
|
7
|
+
};
|
|
8
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
@@ -3,14 +3,18 @@ import { computed } from "#imports";
|
|
|
3
3
|
import {
|
|
4
4
|
getLoopsLmxImageWidth,
|
|
5
5
|
resolveSafeLoopsLmxUrl,
|
|
6
|
-
resolveLoopsLmxVariables
|
|
7
|
-
applyInlineStyles
|
|
6
|
+
resolveLoopsLmxVariables
|
|
8
7
|
} from "@onderwijsin/loops-core";
|
|
8
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
9
9
|
const props = defineProps({
|
|
10
10
|
node: { type: Object, required: true },
|
|
11
11
|
variables: { type: Object, required: true },
|
|
12
12
|
config: { type: Object, required: true }
|
|
13
13
|
});
|
|
14
|
+
const style = useLoopsNodeStyles(
|
|
15
|
+
() => props.node,
|
|
16
|
+
() => props.config
|
|
17
|
+
);
|
|
14
18
|
const source = computed(
|
|
15
19
|
() => resolveSafeLoopsLmxUrl(
|
|
16
20
|
props.node.attributes.dynamicSrc ?? props.node.attributes.src,
|
|
@@ -28,25 +32,9 @@ const width = computed(() => getLoopsLmxImageWidth(props.node.attributes.width))
|
|
|
28
32
|
</script>
|
|
29
33
|
|
|
30
34
|
<template>
|
|
31
|
-
<hr
|
|
32
|
-
v-if="node.name === 'Divider'"
|
|
33
|
-
:style="applyInlineStyles(node.attributes, config.applyInlineStyles !== false)"
|
|
34
|
-
/>
|
|
35
|
+
<hr v-if="node.name === 'Divider'" :style="style" />
|
|
35
36
|
<a v-else-if="source && imageLink" :href="imageLink" rel="noopener noreferrer">
|
|
36
|
-
<img
|
|
37
|
-
:src="source"
|
|
38
|
-
:alt="alt"
|
|
39
|
-
:width="width"
|
|
40
|
-
loading="lazy"
|
|
41
|
-
:style="applyInlineStyles(node.attributes, config.applyInlineStyles !== false)"
|
|
42
|
-
/>
|
|
37
|
+
<img :src="source" :alt="alt" :width="width" loading="lazy" :style="style" />
|
|
43
38
|
</a>
|
|
44
|
-
<img
|
|
45
|
-
v-else-if="source"
|
|
46
|
-
:src="source"
|
|
47
|
-
:alt="alt"
|
|
48
|
-
:width="width"
|
|
49
|
-
loading="lazy"
|
|
50
|
-
:style="applyInlineStyles(node.attributes, config.applyInlineStyles !== false)"
|
|
51
|
-
/>
|
|
39
|
+
<img v-else-if="source" :src="source" :alt="alt" :width="width" loading="lazy" :style="style" />
|
|
52
40
|
</template>
|
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
import { computed } from "#imports";
|
|
3
3
|
import {
|
|
4
4
|
isRenderableLoopsLmxElement,
|
|
5
|
-
resolveSafeLoopsLmxUrl
|
|
6
|
-
applyInlineStyles
|
|
5
|
+
resolveSafeLoopsLmxUrl
|
|
7
6
|
} from "@onderwijsin/loops-core";
|
|
7
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
8
8
|
const props = defineProps({
|
|
9
9
|
node: { type: Object, required: true },
|
|
10
10
|
variables: { type: Object, required: true },
|
|
11
11
|
config: { type: Object, required: true },
|
|
12
12
|
resolveVariables: { type: Boolean, required: false }
|
|
13
13
|
});
|
|
14
|
+
const style = useLoopsNodeStyles(
|
|
15
|
+
() => props.node.type === "element" && props.node.name === "Button" ? props.node : void 0,
|
|
16
|
+
() => props.config
|
|
17
|
+
);
|
|
14
18
|
const isRenderable = computed(
|
|
15
19
|
() => props.node.type === "text" || isRenderableLoopsLmxElement(props.node) || props.node.type === "element" && ["Quote", "Br"].includes(props.node.name)
|
|
16
20
|
);
|
|
@@ -88,7 +92,7 @@ const buttonLink = computed(
|
|
|
88
92
|
:href="buttonLink"
|
|
89
93
|
rel="noopener noreferrer"
|
|
90
94
|
class="no-underline text-inverted"
|
|
91
|
-
:style="
|
|
95
|
+
:style="style"
|
|
92
96
|
>
|
|
93
97
|
<LoopsAstInline
|
|
94
98
|
v-for="(child, index) in node.children"
|
|
@@ -100,7 +104,7 @@ const buttonLink = computed(
|
|
|
100
104
|
</UButton>
|
|
101
105
|
<span
|
|
102
106
|
v-else-if="isRenderable && node.type === 'element' && node.name === 'Button'"
|
|
103
|
-
:style="
|
|
107
|
+
:style="style"
|
|
104
108
|
>
|
|
105
109
|
<LoopsAstInline
|
|
106
110
|
v-for="(child, index) in node.children"
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed } from "#imports";
|
|
3
3
|
import {
|
|
4
|
-
evaluate
|
|
5
|
-
applyInlineStyles
|
|
4
|
+
evaluate
|
|
6
5
|
} from "@onderwijsin/loops-core";
|
|
6
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
7
7
|
const props = defineProps({
|
|
8
8
|
node: { type: Object, required: true },
|
|
9
9
|
variables: { type: Object, required: true },
|
|
10
10
|
config: { type: Object, required: true }
|
|
11
11
|
});
|
|
12
|
+
const style = useLoopsNodeStyles(
|
|
13
|
+
() => props.node,
|
|
14
|
+
() => props.config
|
|
15
|
+
);
|
|
12
16
|
const condition = computed(() => {
|
|
13
17
|
const variable = props.node.attributes.if;
|
|
14
18
|
if (!variable) return null;
|
|
@@ -25,10 +29,7 @@ const isVisible = computed(
|
|
|
25
29
|
</script>
|
|
26
30
|
|
|
27
31
|
<template>
|
|
28
|
-
<section
|
|
29
|
-
v-if="isVisible"
|
|
30
|
-
:style="applyInlineStyles(node.attributes, config.applyInlineStyles !== false)"
|
|
31
|
-
>
|
|
32
|
+
<section v-if="isVisible" :style="style">
|
|
32
33
|
<LoopsAstNode
|
|
33
34
|
v-for="(child, index) in node.children"
|
|
34
35
|
:key="index"
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed } from "#imports";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
} from "@onderwijsin/loops-core";
|
|
3
|
+
import {} from "@onderwijsin/loops-core";
|
|
4
|
+
import { useLoopsNodeStyles } from "../../composables/node-styles";
|
|
6
5
|
const props = defineProps({
|
|
7
6
|
node: { type: Object, required: true },
|
|
8
7
|
variables: { type: Object, required: true },
|
|
9
8
|
config: { type: Object, required: true }
|
|
10
9
|
});
|
|
10
|
+
const style = useLoopsNodeStyles(
|
|
11
|
+
() => props.node,
|
|
12
|
+
() => props.config
|
|
13
|
+
);
|
|
11
14
|
const tag = computed(() => {
|
|
12
15
|
const tags = {
|
|
13
16
|
H1: "h1",
|
|
@@ -26,12 +29,7 @@ const alignmentClass = computed(() => {
|
|
|
26
29
|
</script>
|
|
27
30
|
|
|
28
31
|
<template>
|
|
29
|
-
<component
|
|
30
|
-
v-if="tag"
|
|
31
|
-
:is="tag"
|
|
32
|
-
:class="alignmentClass"
|
|
33
|
-
:style="applyInlineStyles(node.attributes, config.applyInlineStyles !== false)"
|
|
34
|
-
>
|
|
32
|
+
<component v-if="tag" :is="tag" :class="alignmentClass" :style="style">
|
|
35
33
|
<LoopsAstNode
|
|
36
34
|
v-for="(child, index) in node.children"
|
|
37
35
|
:key="index"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ComputedRef } from "vue";
|
|
2
|
+
import type { LoopsLmxElement } from "@onderwijsin/loops-core";
|
|
3
|
+
import type { LoopsRendererConfig } from "../../types.js";
|
|
4
|
+
/** Starts an independent AST background context, including for nested renderer instances. */
|
|
5
|
+
export declare function resetLoopsRendererBackground(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves reactive styles and provides authored background context to descendant nodes.
|
|
8
|
+
*
|
|
9
|
+
* @param node - Styled element getter; undefined lets dispatch components pass context through.
|
|
10
|
+
* @param config - Reactive runtime configuration getter.
|
|
11
|
+
* @returns Computed inline styles with consumer color mappings applied.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useLoopsNodeStyles(node: () => LoopsLmxElement | undefined, config: () => LoopsRendererConfig): ComputedRef<import("@onderwijsin/loops-core").LoopsLmxInlineStyles>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { computed, inject, provide } from "vue";
|
|
2
|
+
import { resolveLoopsRendererStyles } from "../utils/styles.js";
|
|
3
|
+
const backgroundKey = Symbol("loops-background");
|
|
4
|
+
export function resetLoopsRendererBackground() {
|
|
5
|
+
provide(
|
|
6
|
+
backgroundKey,
|
|
7
|
+
computed(() => void 0)
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
export function useLoopsNodeStyles(node, config) {
|
|
11
|
+
const parentBackground = inject(backgroundKey, void 0);
|
|
12
|
+
const resolved = computed(() => {
|
|
13
|
+
const element = node();
|
|
14
|
+
const parent = parentBackground?.value;
|
|
15
|
+
return element ? resolveLoopsRendererStyles(element, config(), parent) : { styles: {}, backgroundColor: parent };
|
|
16
|
+
});
|
|
17
|
+
provide(
|
|
18
|
+
backgroundKey,
|
|
19
|
+
computed(() => resolved.value.backgroundColor)
|
|
20
|
+
);
|
|
21
|
+
return computed(() => resolved.value.styles);
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LoopsRendererColorMap, LoopsRendererColorProperty } from "../../types.js";
|
|
2
|
+
/** A normalized snapshot of a consumer's role-specific palette. */
|
|
3
|
+
export type CompiledColorMap = Map<LoopsRendererColorProperty, ReadonlyMap<string, string>>;
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes supported source hex colors without accepting arbitrary CSS.
|
|
6
|
+
* @param color - A source hex color.
|
|
7
|
+
* @returns Lowercase six-digit hex, or undefined for unsupported values.
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizeSourceColor(color: string): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Copies and validates source keys once when a mapper is created.
|
|
12
|
+
* @param mappings - Trusted application palettes, separated by CSS role.
|
|
13
|
+
* @returns Normalized source palettes independent of later input mutations.
|
|
14
|
+
*/
|
|
15
|
+
export declare function compileColorMap(mappings: LoopsRendererColorMap): CompiledColorMap;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { toEntries } from "@onderwijsin/nuxt-module-utils/shared";
|
|
2
|
+
export function normalizeSourceColor(color) {
|
|
3
|
+
if (!/^#[\da-f]{3}(?:[\da-f]{3})?$/i.test(color)) return void 0;
|
|
4
|
+
const hex = color.toLowerCase();
|
|
5
|
+
return hex.length === 4 ? `#${hex.slice(1).split("").map((channel) => channel + channel).join("")}` : hex;
|
|
6
|
+
}
|
|
7
|
+
export function compileColorMap(mappings) {
|
|
8
|
+
const compiled = /* @__PURE__ */ new Map();
|
|
9
|
+
for (const [property, palette] of toEntries(mappings)) {
|
|
10
|
+
if (!palette) continue;
|
|
11
|
+
const normalized = /* @__PURE__ */ new Map();
|
|
12
|
+
for (const [source, target] of toEntries(palette)) {
|
|
13
|
+
const color = normalizeSourceColor(source);
|
|
14
|
+
if (!color) throw new TypeError(`Invalid source color in ${property}: ${source}`);
|
|
15
|
+
if (normalized.has(color))
|
|
16
|
+
throw new TypeError(`Duplicate normalized source color in ${property}: ${color}`);
|
|
17
|
+
normalized.set(color, target);
|
|
18
|
+
}
|
|
19
|
+
compiled.set(property, normalized);
|
|
20
|
+
}
|
|
21
|
+
return compiled;
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LoopsRendererColorMap, LoopsRendererColorMapper, LoopsRendererColorMappingOptions } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates the exact-first mapper selected by the module's approximation opt-in.
|
|
4
|
+
* @param mappings - Source hex to trusted CSS colors, separated by CSS role.
|
|
5
|
+
* @param options - Maximum allowed source-color distance, defaulting to 0.03.
|
|
6
|
+
* @returns A synchronous mapper; unmatched or distant colors retain their original values.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createLoopsColorMapper(mappings: LoopsRendererColorMap, options?: LoopsRendererColorMappingOptions): LoopsRendererColorMapper;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isFiniteNumber } from "@onderwijsin/nuxt-module-utils/shared";
|
|
2
|
+
import { compileColorMap, normalizeSourceColor } from "./color-map.js";
|
|
3
|
+
import { oklabDistance, sourceHexToOklab } from "./oklab.js";
|
|
4
|
+
export function createLoopsColorMapper(mappings, options = {}) {
|
|
5
|
+
const maxDeltaE = options.maxDeltaE ?? 0.03;
|
|
6
|
+
if (!isFiniteNumber(maxDeltaE) || maxDeltaE < 0) {
|
|
7
|
+
throw new RangeError("maxDeltaE must be a finite, non-negative OKLab distance.");
|
|
8
|
+
}
|
|
9
|
+
const compiled = compileColorMap(mappings);
|
|
10
|
+
const candidates = new Map(
|
|
11
|
+
[...compiled].map(([property, palette]) => [
|
|
12
|
+
property,
|
|
13
|
+
[...palette].sort(([first], [second]) => first < second ? -1 : first > second ? 1 : 0).map(([source, target]) => ({ target, lab: sourceHexToOklab(source) }))
|
|
14
|
+
])
|
|
15
|
+
);
|
|
16
|
+
return (color, context) => {
|
|
17
|
+
const source = normalizeSourceColor(color);
|
|
18
|
+
if (!source) return void 0;
|
|
19
|
+
const exact = compiled.get(context.property)?.get(source);
|
|
20
|
+
if (exact !== void 0) return exact;
|
|
21
|
+
const lab = sourceHexToOklab(source);
|
|
22
|
+
let nearestDistance = Infinity;
|
|
23
|
+
let nearest;
|
|
24
|
+
for (const candidate of candidates.get(context.property) ?? []) {
|
|
25
|
+
const distance = oklabDistance(lab, candidate.lab);
|
|
26
|
+
if (distance <= maxDeltaE && distance < nearestDistance) {
|
|
27
|
+
nearestDistance = distance;
|
|
28
|
+
nearest = candidate.target;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return nearest;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LoopsRendererColorMap, LoopsRendererColorMapper, LoopsRendererColorMappingOptions } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates the exact-only mapper selected when approximation is disabled.
|
|
4
|
+
* @param mappings - Source hex to trusted CSS colors, separated by CSS role.
|
|
5
|
+
* @param _options - Shared utility options; distance has no effect in an exact-only build.
|
|
6
|
+
* @returns A synchronous mapper that retains unmatched source colors.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createLoopsColorMapper(mappings: LoopsRendererColorMap, _options?: LoopsRendererColorMappingOptions): LoopsRendererColorMapper;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { compileColorMap, normalizeSourceColor } from "./color-map.js";
|
|
2
|
+
export function createLoopsColorMapper(mappings, _options) {
|
|
3
|
+
const compiled = compileColorMap(mappings);
|
|
4
|
+
return (color, context) => {
|
|
5
|
+
const source = normalizeSourceColor(color);
|
|
6
|
+
return source ? compiled.get(context.property)?.get(source) : void 0;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Coordinates for Euclidean color-distance comparisons in OKLab. */
|
|
2
|
+
export interface OklabColor {
|
|
3
|
+
lightness: number;
|
|
4
|
+
a: number;
|
|
5
|
+
b: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Converts normalized sRGB hex into OKLab using linear-light sRGB and the OKLab matrices.
|
|
9
|
+
* See https://www.w3.org/TR/css-color-4/#color-conversion-code.
|
|
10
|
+
* @param hex - A validated six-digit source hex color.
|
|
11
|
+
* @returns OKLab coordinates; this never transforms a rendered color or target CSS token.
|
|
12
|
+
*/
|
|
13
|
+
export declare function sourceHexToOklab(hex: string): OklabColor;
|
|
14
|
+
/**
|
|
15
|
+
* Measures perceptual source-color distance without interpreting mapped CSS values.
|
|
16
|
+
* @param first - First source color in OKLab.
|
|
17
|
+
* @param second - Second source color in OKLab.
|
|
18
|
+
* @returns Euclidean OKLab distance (Delta E OK, with lightness on a 0–1 scale).
|
|
19
|
+
*/
|
|
20
|
+
export declare function oklabDistance(first: OklabColor, second: OklabColor): number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function sourceHexToOklab(hex) {
|
|
2
|
+
const red = linearChannel(hex.slice(1, 3));
|
|
3
|
+
const green = linearChannel(hex.slice(3, 5));
|
|
4
|
+
const blue = linearChannel(hex.slice(5, 7));
|
|
5
|
+
const l = Math.cbrt(0.4122214708 * red + 0.5363325363 * green + 0.0514459929 * blue);
|
|
6
|
+
const m = Math.cbrt(0.2119034982 * red + 0.6806995451 * green + 0.1073969566 * blue);
|
|
7
|
+
const s = Math.cbrt(0.0883024619 * red + 0.2817188376 * green + 0.6299787005 * blue);
|
|
8
|
+
return {
|
|
9
|
+
lightness: 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
10
|
+
a: 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
11
|
+
b: 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function linearChannel(hex) {
|
|
15
|
+
const value = Number.parseInt(hex, 16) / 255;
|
|
16
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
17
|
+
}
|
|
18
|
+
export function oklabDistance(first, second) {
|
|
19
|
+
return Math.hypot(first.lightness - second.lightness, first.a - second.a, first.b - second.b);
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type LoopsLmxElement, type LoopsLmxInlineStyles } from "@onderwijsin/loops-core";
|
|
2
|
+
import type { LoopsRendererConfig } from "../../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Validates source styles before applying trusted consumer color policy.
|
|
5
|
+
*
|
|
6
|
+
* @param node - The authored element to render.
|
|
7
|
+
* @param config - Runtime renderer settings.
|
|
8
|
+
* @param parentBackgroundColor - Nearest authored ancestor background, if known.
|
|
9
|
+
* @returns Mapped styles and the unmapped background context for descendants.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveLoopsRendererStyles(node: LoopsLmxElement, config: LoopsRendererConfig, parentBackgroundColor?: string): {
|
|
12
|
+
styles: LoopsLmxInlineStyles;
|
|
13
|
+
backgroundColor: string | undefined;
|
|
14
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyInlineStyles
|
|
3
|
+
} from "@onderwijsin/loops-core";
|
|
4
|
+
const colorProperties = ["color", "backgroundColor", "borderColor"];
|
|
5
|
+
export function resolveLoopsRendererStyles(node, config, parentBackgroundColor) {
|
|
6
|
+
const styles = applyInlineStyles(node.attributes, config.applyInlineStyles !== false);
|
|
7
|
+
const backgroundColor = styles.backgroundColor ?? parentBackgroundColor;
|
|
8
|
+
if (!config.mapColor) return { styles, backgroundColor };
|
|
9
|
+
const colors = Object.freeze({
|
|
10
|
+
...styles.color ? { color: styles.color } : {},
|
|
11
|
+
...styles.backgroundColor ? { backgroundColor: styles.backgroundColor } : {},
|
|
12
|
+
...styles.borderColor ? { borderColor: styles.borderColor } : {}
|
|
13
|
+
});
|
|
14
|
+
for (const property of colorProperties) {
|
|
15
|
+
const color = colors[property];
|
|
16
|
+
if (color === void 0) continue;
|
|
17
|
+
styles[property] = config.mapColor(color, {
|
|
18
|
+
property,
|
|
19
|
+
nodeType: node.type,
|
|
20
|
+
nodeName: node.name,
|
|
21
|
+
colors,
|
|
22
|
+
backgroundColor,
|
|
23
|
+
parentBackgroundColor,
|
|
24
|
+
sourceTheme: config.sourceTheme,
|
|
25
|
+
targetTheme: config.targetTheme
|
|
26
|
+
}) ?? color;
|
|
27
|
+
}
|
|
28
|
+
return { styles, backgroundColor };
|
|
29
|
+
}
|
package/dist/runtime/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@source "./app";
|
|
1
|
+
@source "./app";@plugin "@tailwindcss/typography";
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EvaluateLoopsLmxOptions } from "@onderwijsin/loops-core";
|
|
2
|
+
/** Authored or application-selected theme; the renderer never detects it automatically. */
|
|
3
|
+
export type LoopsRendererTheme = "light" | "dark";
|
|
4
|
+
/** Validated CSS color declarations supported by the renderer. */
|
|
5
|
+
export type LoopsRendererColorProperty = "color" | "backgroundColor" | "borderColor";
|
|
6
|
+
/** Original validated node colors, before any consumer mapping is applied. */
|
|
7
|
+
export type LoopsRendererColors = Readonly<Partial<Record<LoopsRendererColorProperty, string>>>;
|
|
8
|
+
/** Source context for consumer-owned color policy. All colors are unmapped source values. */
|
|
9
|
+
export interface LoopsRendererColorContext {
|
|
10
|
+
readonly property: LoopsRendererColorProperty;
|
|
11
|
+
readonly nodeType: "element";
|
|
12
|
+
readonly nodeName: string;
|
|
13
|
+
readonly colors: LoopsRendererColors;
|
|
14
|
+
/** Nearest explicit background on this node or an ancestor; excludes host CSS. */
|
|
15
|
+
readonly backgroundColor: string | undefined;
|
|
16
|
+
/** Nearest explicit ancestor background, before this node's own background. */
|
|
17
|
+
readonly parentBackgroundColor: string | undefined;
|
|
18
|
+
readonly sourceTheme: LoopsRendererTheme | undefined;
|
|
19
|
+
readonly targetTheme: LoopsRendererTheme | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** Returns a trusted CSS color (including var(...)), or undefined to keep the original. */
|
|
22
|
+
export type LoopsRendererColorMapper = (color: string, context: LoopsRendererColorContext) => string | undefined;
|
|
23
|
+
/** Consumer-owned source hex to trusted CSS color mappings, separated by CSS role. */
|
|
24
|
+
export type LoopsRendererColorMap = Partial<Record<LoopsRendererColorProperty, Readonly<Record<string, string>>>>;
|
|
25
|
+
/** Options for the build-selected color mapper utility. */
|
|
26
|
+
export interface LoopsRendererColorMappingOptions {
|
|
27
|
+
/** Maximum Euclidean OKLab distance; defaults to 0.03 when approximation is enabled. */
|
|
28
|
+
maxDeltaE?: number;
|
|
29
|
+
}
|
|
2
30
|
/** Options shared by the root renderer and every recursive LMX node renderer. */
|
|
3
|
-
export
|
|
31
|
+
export interface LoopsRendererConfig {
|
|
32
|
+
/** Apply validated authored styles; false also disables color mapping. */
|
|
33
|
+
applyInlineStyles?: boolean;
|
|
34
|
+
/** Conditional evaluation fallbacks. */
|
|
35
|
+
evaluate?: EvaluateLoopsLmxOptions;
|
|
36
|
+
/** Theme in which source colors were authored. Omitted means unknown. */
|
|
37
|
+
sourceTheme?: LoopsRendererTheme;
|
|
4
38
|
/** Render unsupported nodes in an inline developer-only block. */
|
|
5
39
|
debug?: boolean;
|
|
6
|
-
|
|
40
|
+
/** Application-owned target theme. Omitted themes remain unknown. */
|
|
41
|
+
targetTheme?: LoopsRendererTheme;
|
|
42
|
+
/** Runtime-only policy, applied after source validation to supported colors only. */
|
|
43
|
+
mapColor?: LoopsRendererColorMapper;
|
|
44
|
+
}
|
package/dist/types.d.mts
CHANGED
|
@@ -4,4 +4,6 @@ import type { default as Module } from './module.mjs'
|
|
|
4
4
|
|
|
5
5
|
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
6
|
|
|
7
|
+
export { type LoopsRendererColorContext, type LoopsRendererColorMap, type LoopsRendererColorMapper, type LoopsRendererColorMappingOptions, type LoopsRendererColorProperty, type LoopsRendererColors, type LoopsRendererConfig, type LoopsRendererTheme } from '../dist/runtime/types.js'
|
|
8
|
+
|
|
7
9
|
export { default } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onderwijsin/nuxt-loops-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Nuxt module for rendering Loops LMX email content.",
|
|
5
5
|
"homepage": "https://github.com/onderwijsin/nuxt-modules#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@nuxt/kit": "4.5.2",
|
|
38
38
|
"@nuxt/schema": "4.5.2",
|
|
39
|
-
"@nuxt/ui": "4.10.0",
|
|
40
39
|
"@onderwijsin/loops-core": "1.3.0",
|
|
41
40
|
"@tailwindcss/typography": "0.5.20",
|
|
42
41
|
"defu": "6.1.7",
|
|
@@ -47,16 +46,20 @@
|
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@nuxt/module-builder": "1.0.3",
|
|
49
|
+
"@nuxt/ui": "4.10.0",
|
|
50
50
|
"nuxt": "4.5.2",
|
|
51
51
|
"typescript": "5.9.3",
|
|
52
52
|
"unbuild": "3.6.1"
|
|
53
53
|
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@nuxt/ui": "^4.0.0"
|
|
56
|
+
},
|
|
54
57
|
"engines": {
|
|
55
58
|
"node": ">=24"
|
|
56
59
|
},
|
|
57
60
|
"scripts": {
|
|
58
61
|
"build": "nuxt-module-build build",
|
|
59
|
-
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
62
|
+
"typecheck": "vue-tsc --noEmit --project tsconfig.json",
|
|
60
63
|
"dev": "pnpm run dev:prepare && nuxt dev playground",
|
|
61
64
|
"dev:build": "nuxt build playground",
|
|
62
65
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && nuxt prepare playground"
|