@fluxdown/solid 0.0.0-stage → 0.2.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/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/cjs/assets/raw-Dob3BCyv.css +56 -0
- package/dist/cjs/chunks/raw-DlzW8_Im.cjs +609 -0
- package/dist/cjs/components/block-reconciler/index.d.cts +2 -0
- package/dist/cjs/components/block-reconciler/type.d.cts +22 -0
- package/dist/cjs/components/block-reconciler/utils.d.cts +2 -0
- package/dist/cjs/components/index.d.cts +2 -0
- package/dist/cjs/components/root-reconciler/index.d.cts +6 -0
- package/dist/cjs/consts/config.d.cts +2 -0
- package/dist/cjs/consts/defaults.d.cts +2 -0
- package/dist/cjs/consts/index.d.cts +4 -0
- package/dist/cjs/consts/smooth.d.cts +3 -0
- package/dist/cjs/consts/styles.d.cts +1 -0
- package/dist/cjs/context/index.d.cts +1 -0
- package/dist/cjs/context/render/index.d.cts +6 -0
- package/dist/cjs/env.d.cts +1 -0
- package/dist/cjs/full.browser.cjs +2 -0
- package/dist/cjs/full.cjs +13 -0
- package/dist/cjs/hooks/index.d.cts +1 -0
- package/dist/cjs/hooks/plugins.d.cts +6 -0
- package/dist/cjs/lite.browser.cjs +2 -0
- package/dist/cjs/lite.cjs +13 -0
- package/dist/cjs/modules/index.d.cts +1 -0
- package/dist/cjs/modules/solid-renderer/index.d.cts +9 -0
- package/dist/cjs/modules/solid-renderer/type.d.cts +4 -0
- package/dist/cjs/packs/full/index.d.cts +5 -0
- package/dist/cjs/packs/full/type.d.cts +3 -0
- package/dist/cjs/packs/lite/index.d.cts +5 -0
- package/dist/cjs/packs/lite/type.d.cts +3 -0
- package/dist/cjs/packs/raw/index.d.cts +5 -0
- package/dist/cjs/packs/raw/type.d.cts +77 -0
- package/dist/cjs/packs/raw/utils.d.cts +2 -0
- package/dist/cjs/packs/utils/config.d.cts +13 -0
- package/dist/cjs/packs/utils/effect.d.cts +4 -0
- package/dist/cjs/packs/utils/index.d.cts +3 -0
- package/dist/cjs/packs/utils/patches.d.cts +2 -0
- package/dist/cjs/raw.browser.cjs +2 -0
- package/dist/cjs/raw.cjs +3 -0
- package/dist/cjs/server/full.cjs +13 -0
- package/dist/cjs/server/lite.cjs +13 -0
- package/dist/cjs/server/raw.cjs +593 -0
- package/dist/cjs/styles.css +2 -0
- package/dist/cjs/theme/consts.d.cts +4 -0
- package/dist/cjs/theme/hooks.d.cts +2 -0
- package/dist/cjs/theme/index.d.cts +1 -0
- package/dist/cjs/theme/presets/base.d.cts +2 -0
- package/dist/cjs/theme/presets/dark.d.cts +2 -0
- package/dist/cjs/theme/presets/index.d.cts +4 -0
- package/dist/cjs/theme/presets/light.d.cts +2 -0
- package/dist/cjs/theme/utils.d.cts +4 -0
- package/dist/cjs/types/index.d.cts +2 -0
- package/dist/cjs/types/theme.d.cts +138 -0
- package/dist/esm/assets/raw-Dob3BCyv.css +56 -0
- package/dist/esm/chunks/raw-ULd4Y10B.js +598 -0
- package/dist/esm/components/block-reconciler/index.d.ts +2 -0
- package/dist/esm/components/block-reconciler/type.d.ts +22 -0
- package/dist/esm/components/block-reconciler/utils.d.ts +2 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/root-reconciler/index.d.ts +6 -0
- package/dist/esm/consts/config.d.ts +2 -0
- package/dist/esm/consts/defaults.d.ts +2 -0
- package/dist/esm/consts/index.d.ts +4 -0
- package/dist/esm/consts/smooth.d.ts +3 -0
- package/dist/esm/consts/styles.d.ts +1 -0
- package/dist/esm/context/index.d.ts +1 -0
- package/dist/esm/context/render/index.d.ts +6 -0
- package/dist/esm/env.d.ts +1 -0
- package/dist/esm/full.browser.js +2 -0
- package/dist/esm/full.js +12 -0
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/plugins.d.ts +6 -0
- package/dist/esm/lite.browser.js +2 -0
- package/dist/esm/lite.js +12 -0
- package/dist/esm/modules/index.d.ts +1 -0
- package/dist/esm/modules/solid-renderer/index.d.ts +9 -0
- package/dist/esm/modules/solid-renderer/type.d.ts +4 -0
- package/dist/esm/packs/full/index.d.ts +5 -0
- package/dist/esm/packs/full/type.d.ts +3 -0
- package/dist/esm/packs/lite/index.d.ts +5 -0
- package/dist/esm/packs/lite/type.d.ts +3 -0
- package/dist/esm/packs/raw/index.d.ts +5 -0
- package/dist/esm/packs/raw/type.d.ts +77 -0
- package/dist/esm/packs/raw/utils.d.ts +2 -0
- package/dist/esm/packs/utils/config.d.ts +13 -0
- package/dist/esm/packs/utils/effect.d.ts +4 -0
- package/dist/esm/packs/utils/index.d.ts +3 -0
- package/dist/esm/packs/utils/patches.d.ts +2 -0
- package/dist/esm/raw.browser.js +2 -0
- package/dist/esm/raw.js +2 -0
- package/dist/esm/server/full.js +12 -0
- package/dist/esm/server/lite.js +12 -0
- package/dist/esm/server/raw.js +591 -0
- package/dist/esm/styles.css +2 -0
- package/dist/esm/theme/consts.d.ts +4 -0
- package/dist/esm/theme/hooks.d.ts +2 -0
- package/dist/esm/theme/index.d.ts +1 -0
- package/dist/esm/theme/presets/base.d.ts +2 -0
- package/dist/esm/theme/presets/dark.d.ts +2 -0
- package/dist/esm/theme/presets/index.d.ts +4 -0
- package/dist/esm/theme/presets/light.d.ts +2 -0
- package/dist/esm/theme/utils.d.ts +4 -0
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/theme.d.ts +138 -0
- package/package.json +121 -3
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import { Dynamic, createComponent, getNextElement, insert, mergeProps, runHydrationEvents, spread, template } from "solid-js/web";
|
|
2
|
+
import { BaseRenderer, Core, isPluggablesEqual, isPluginSetEqual } from "@fluxdown/core";
|
|
3
|
+
import { PRESET_MAPPER_PLUGINS } from "@fluxdown/core-plugins/presets/mapper";
|
|
4
|
+
import { PREFIX, SlotProvider, createStateOf, createStateValue, filterDisabledBy, getSolidProps, isHastElement, isHastParent, toPluginList } from "@fluxdown/solid-plugins/base";
|
|
5
|
+
import { castArray, defaults, forOwn, isArray, isBoolean, isNumber, isObject, isObjectLike, isString, mapValues, merge, replace, toLower, toString } from "lodash-es";
|
|
6
|
+
import { shallowEqual } from "shallow-equal";
|
|
7
|
+
import { For, createContext, createMemo, createUniqueId, mergeProps as mergeProps$1, onCleanup, splitProps, useContext } from "solid-js";
|
|
8
|
+
import { D, S, render, toState } from "stative";
|
|
9
|
+
import { PluginPriority } from "@fluxdown/types";
|
|
10
|
+
import { IntervalSmoothTicker, RafSmoothTicker, SpringSmoothScheduler } from "@fluxdown/core-plugins/plugins/mapper/smooth";
|
|
11
|
+
import { assert, defaultsBy, isEnableRAF } from "@fluxdown/utils";
|
|
12
|
+
//#region src/context/render/index.ts
|
|
13
|
+
var RenderContext = /*#__PURE__*/ createContext(null);
|
|
14
|
+
var RenderProvider = RenderContext.Provider;
|
|
15
|
+
var useRender = () => {
|
|
16
|
+
const config = useContext(RenderContext);
|
|
17
|
+
if (config === null) throw new Error("[Fluxdown] A render context is required.");
|
|
18
|
+
return config;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/components/block-reconciler/utils.tsx
|
|
22
|
+
var isElementContent = (node) => {
|
|
23
|
+
return node.type === "comment" || node.type === "element" || node.type === "text";
|
|
24
|
+
};
|
|
25
|
+
var getChildKey = (node, fallbackIndex) => {
|
|
26
|
+
if (node.type === "element" && node.properties?.dataParserPatch === "1" && isString(node.properties.dataPatchKey)) return `patch:${node.properties.dataPatchKey}`;
|
|
27
|
+
if (isString(node.data?.renderKey)) return `render:${node.data.renderKey}`;
|
|
28
|
+
const tagName = node.type === "element" ? `:${node.tagName}` : "";
|
|
29
|
+
if (node.position?.start.offset !== void 0) return `source:${node.position.start.offset}:${node.type}${tagName}`;
|
|
30
|
+
return `${fallbackIndex}:${node.type}${tagName}`;
|
|
31
|
+
};
|
|
32
|
+
var ChildrenReconciler = (props) => {
|
|
33
|
+
const nodes = createMemo(() => {
|
|
34
|
+
const children = props.node?.children ?? [];
|
|
35
|
+
const result = /* @__PURE__ */ new Map();
|
|
36
|
+
children.forEach((child, index) => {
|
|
37
|
+
if (!isElementContent(child)) return;
|
|
38
|
+
const previous = children[index - 1];
|
|
39
|
+
const key = child.type === "text" ? `text:${previous ? getChildKey(previous, index - 1) : "start"}` : getChildKey(child, index);
|
|
40
|
+
result.set(result.has(key) ? `fallback:${index}` : key, child);
|
|
41
|
+
});
|
|
42
|
+
return result;
|
|
43
|
+
});
|
|
44
|
+
const keys = createMemo(() => [...nodes().keys()]);
|
|
45
|
+
return createComponent(For, {
|
|
46
|
+
get each() {
|
|
47
|
+
return keys();
|
|
48
|
+
},
|
|
49
|
+
children: (key) => {
|
|
50
|
+
return createComponent(NodeReconciler, mergeProps(props, { get node() {
|
|
51
|
+
return nodes().get(key);
|
|
52
|
+
} }));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
var NodeReconciler = (props) => {
|
|
57
|
+
const childParents = createMemo(() => {
|
|
58
|
+
const node = props.node;
|
|
59
|
+
return node && isHastParent(node) ? [...props.parents, node] : props.parents;
|
|
60
|
+
});
|
|
61
|
+
const render = (node) => {
|
|
62
|
+
return createComponent(NodeReconciler, mergeProps(props, {
|
|
63
|
+
get node() {
|
|
64
|
+
return typeof node === "function" ? node() : node;
|
|
65
|
+
},
|
|
66
|
+
get parents() {
|
|
67
|
+
return childParents();
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
};
|
|
71
|
+
const renderChildren = (target) => {
|
|
72
|
+
const current = target === void 0 || target === props.node;
|
|
73
|
+
const node = () => {
|
|
74
|
+
const value = current ? props.node : typeof target === "function" ? target() : target;
|
|
75
|
+
return value && isHastParent(value) ? value : void 0;
|
|
76
|
+
};
|
|
77
|
+
const parents = () => {
|
|
78
|
+
const value = node();
|
|
79
|
+
return current || !value ? childParents() : [...childParents(), value];
|
|
80
|
+
};
|
|
81
|
+
return createComponent(ChildrenReconciler, mergeProps(props, {
|
|
82
|
+
get node() {
|
|
83
|
+
return node();
|
|
84
|
+
},
|
|
85
|
+
get parents() {
|
|
86
|
+
return parents();
|
|
87
|
+
}
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
const getProps = (target) => {
|
|
91
|
+
if (props.getProps === null) return {};
|
|
92
|
+
const node = props.node;
|
|
93
|
+
const current = target ?? (node && isHastElement(node) ? node : void 0);
|
|
94
|
+
return props.getProps ? props.getProps(current) : { ...current?.properties };
|
|
95
|
+
};
|
|
96
|
+
const matched = createMemo(() => {
|
|
97
|
+
const node = props.node;
|
|
98
|
+
if (!node) return;
|
|
99
|
+
let result;
|
|
100
|
+
let priority = Infinity;
|
|
101
|
+
for (const plugin of props.plugins) {
|
|
102
|
+
const nextPriority = plugin.config.priority ?? PluginPriority.Default;
|
|
103
|
+
if (nextPriority > priority || !plugin.match({
|
|
104
|
+
node,
|
|
105
|
+
parents: props.parents
|
|
106
|
+
})) continue;
|
|
107
|
+
result = plugin;
|
|
108
|
+
priority = nextPriority;
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
});
|
|
112
|
+
const Renderer = createMemo(() => {
|
|
113
|
+
const plugin = matched();
|
|
114
|
+
return plugin?.render.bind(plugin);
|
|
115
|
+
});
|
|
116
|
+
return createComponent(Dynamic, mergeProps({ get component() {
|
|
117
|
+
return Renderer();
|
|
118
|
+
} }, mergeProps$1(props, {
|
|
119
|
+
getProps,
|
|
120
|
+
render,
|
|
121
|
+
renderChildren
|
|
122
|
+
}), { get node() {
|
|
123
|
+
return props.node;
|
|
124
|
+
} }));
|
|
125
|
+
};
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/components/block-reconciler/index.tsx
|
|
128
|
+
var BlockReconciler = (props) => {
|
|
129
|
+
const config = useRender();
|
|
130
|
+
const root = createStateValue(() => props.block.value);
|
|
131
|
+
const patches = createMemo(() => toState(props.patches));
|
|
132
|
+
const plugins = createStateValue(() => toState(props.plugins));
|
|
133
|
+
return createComponent(ChildrenReconciler, {
|
|
134
|
+
get node() {
|
|
135
|
+
return root();
|
|
136
|
+
},
|
|
137
|
+
get parents() {
|
|
138
|
+
return [root()];
|
|
139
|
+
},
|
|
140
|
+
get patches() {
|
|
141
|
+
return patches();
|
|
142
|
+
},
|
|
143
|
+
get plugins() {
|
|
144
|
+
return plugins();
|
|
145
|
+
},
|
|
146
|
+
get getProps() {
|
|
147
|
+
return config.getProps;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/components/root-reconciler/index.tsx
|
|
153
|
+
var RootReconciler = (props) => {
|
|
154
|
+
const value = createStateValue(() => props.value);
|
|
155
|
+
const blocks = createMemo(() => {
|
|
156
|
+
const entries = value();
|
|
157
|
+
return new Map(entries.map((block) => [block.key, block]));
|
|
158
|
+
});
|
|
159
|
+
const keys = createMemo(() => [...blocks().keys()]);
|
|
160
|
+
return createComponent(For, {
|
|
161
|
+
get each() {
|
|
162
|
+
return keys();
|
|
163
|
+
},
|
|
164
|
+
children: (key) => {
|
|
165
|
+
return createComponent(BlockReconciler, mergeProps(() => blocks().get(key)));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/consts/config.ts
|
|
171
|
+
var DEFAULT_CONFIG = {
|
|
172
|
+
footnote: false,
|
|
173
|
+
repair: true,
|
|
174
|
+
repairEnding: false,
|
|
175
|
+
tex: false,
|
|
176
|
+
indentedCode: false,
|
|
177
|
+
setextHeading: false
|
|
178
|
+
};
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/consts/defaults.ts
|
|
181
|
+
var EL = [];
|
|
182
|
+
var EO = {};
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/consts/smooth.ts
|
|
185
|
+
var ALL_TICKERS = [RafSmoothTicker, IntervalSmoothTicker];
|
|
186
|
+
var ALL_SCHEDULERS = [SpringSmoothScheduler];
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/consts/styles.ts
|
|
189
|
+
var ROOT_CLASS_NAME = `${PREFIX}-root`;
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/hooks/plugins.ts
|
|
192
|
+
var createPlugins = (items, type) => {
|
|
193
|
+
return createMemo(() => toPluginList(items(), type));
|
|
194
|
+
};
|
|
195
|
+
var createMergedPlugins = (presets, plugins) => {
|
|
196
|
+
return createMemo(() => {
|
|
197
|
+
const items = castArray(plugins() ?? EL);
|
|
198
|
+
const merge = (type) => {
|
|
199
|
+
const overrides = toPluginList(items, type);
|
|
200
|
+
return [...filterDisabledBy(toPluginList(presets, type), overrides), ...overrides];
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
remarks: merge("remarks"),
|
|
204
|
+
rehypes: merge("rehypes"),
|
|
205
|
+
repairs: merge("repairs"),
|
|
206
|
+
mappers: merge("mappers"),
|
|
207
|
+
renders: merge("renders"),
|
|
208
|
+
slots: merge("slots")
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/modules/solid-renderer/index.tsx
|
|
214
|
+
var SolidRenderer = class extends BaseRenderer {
|
|
215
|
+
renderItem(item) {
|
|
216
|
+
const { patches, plugins } = this.inputs;
|
|
217
|
+
return {
|
|
218
|
+
key: item.meta.value.key,
|
|
219
|
+
block: item,
|
|
220
|
+
patches,
|
|
221
|
+
plugins
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
var index_module_default = { root: "_root_f61oc_1" };
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/theme/presets/base.ts
|
|
228
|
+
var BASE_TOKENS = {
|
|
229
|
+
typography: {
|
|
230
|
+
fontSans: "Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif",
|
|
231
|
+
fontMono: "'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace",
|
|
232
|
+
fontSmoothing: "antialiased",
|
|
233
|
+
fontSize: {
|
|
234
|
+
xs: "0.75rem",
|
|
235
|
+
sm: "0.875rem",
|
|
236
|
+
md: "1rem"
|
|
237
|
+
},
|
|
238
|
+
lineHeight: {
|
|
239
|
+
sm: 1.4,
|
|
240
|
+
md: 1.65,
|
|
241
|
+
lg: 1.8
|
|
242
|
+
},
|
|
243
|
+
fontWeight: {
|
|
244
|
+
normal: 400,
|
|
245
|
+
medium: 600,
|
|
246
|
+
bold: 650
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
heading: {
|
|
250
|
+
h1: {
|
|
251
|
+
fontSize: "2rem",
|
|
252
|
+
fontWeight: 650,
|
|
253
|
+
lineHeight: 1.25,
|
|
254
|
+
marginTop: "2rem",
|
|
255
|
+
marginBottom: "1rem"
|
|
256
|
+
},
|
|
257
|
+
h2: {
|
|
258
|
+
fontSize: "1.5rem",
|
|
259
|
+
fontWeight: 650,
|
|
260
|
+
lineHeight: 1.3,
|
|
261
|
+
marginTop: "1.75rem",
|
|
262
|
+
marginBottom: "0.875rem"
|
|
263
|
+
},
|
|
264
|
+
h3: {
|
|
265
|
+
fontSize: "1.25rem",
|
|
266
|
+
fontWeight: 600,
|
|
267
|
+
lineHeight: 1.4,
|
|
268
|
+
marginTop: "1.5rem",
|
|
269
|
+
marginBottom: "0.75rem"
|
|
270
|
+
},
|
|
271
|
+
h4: {
|
|
272
|
+
fontSize: "1.125rem",
|
|
273
|
+
fontWeight: 600,
|
|
274
|
+
lineHeight: 1.4,
|
|
275
|
+
marginTop: "1.25rem",
|
|
276
|
+
marginBottom: "0.625rem"
|
|
277
|
+
},
|
|
278
|
+
h5: {
|
|
279
|
+
fontSize: "1rem",
|
|
280
|
+
fontWeight: 600,
|
|
281
|
+
lineHeight: 1.5,
|
|
282
|
+
marginTop: "1rem",
|
|
283
|
+
marginBottom: "0.5rem"
|
|
284
|
+
},
|
|
285
|
+
h6: {
|
|
286
|
+
fontSize: "0.875rem",
|
|
287
|
+
fontWeight: 600,
|
|
288
|
+
lineHeight: 1.5,
|
|
289
|
+
marginTop: "1rem",
|
|
290
|
+
marginBottom: "0.5rem"
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
paragraph: {
|
|
294
|
+
marginTop: "0",
|
|
295
|
+
marginBottom: "1rem"
|
|
296
|
+
},
|
|
297
|
+
code: {
|
|
298
|
+
fontSize: "0.875rem",
|
|
299
|
+
lineHeight: 1.65
|
|
300
|
+
},
|
|
301
|
+
inlineCode: {
|
|
302
|
+
paddingBlock: "0.15em",
|
|
303
|
+
paddingInline: "0.35em",
|
|
304
|
+
border: `1px solid var(--${PREFIX}-colors-border)`,
|
|
305
|
+
borderRadius: `var(--${PREFIX}-radius-sm)`,
|
|
306
|
+
background: `var(--${PREFIX}-colors-surface-muted)`,
|
|
307
|
+
fontFamily: `var(--${PREFIX}-typography-font-mono)`,
|
|
308
|
+
fontSize: "0.875em",
|
|
309
|
+
whiteSpace: "break-spaces"
|
|
310
|
+
},
|
|
311
|
+
divider: {
|
|
312
|
+
height: "1px",
|
|
313
|
+
marginBlock: `var(--${PREFIX}-spacing-xl)`,
|
|
314
|
+
marginInline: "0",
|
|
315
|
+
border: "0",
|
|
316
|
+
borderBlockEnd: `var(--${PREFIX}-divider-border)`,
|
|
317
|
+
background: `var(--${PREFIX}-colors-border)`
|
|
318
|
+
},
|
|
319
|
+
footnotes: {
|
|
320
|
+
marginTop: `var(--${PREFIX}-spacing-xl)`,
|
|
321
|
+
paddingTop: `var(--${PREFIX}-spacing-lg)`,
|
|
322
|
+
borderTop: `1px solid var(--${PREFIX}-colors-border)`,
|
|
323
|
+
color: `var(--${PREFIX}-colors-fg-muted)`,
|
|
324
|
+
fontSize: `var(--${PREFIX}-typography-font-size-sm)`
|
|
325
|
+
},
|
|
326
|
+
radius: {
|
|
327
|
+
sm: "0.25rem",
|
|
328
|
+
md: "0.5rem",
|
|
329
|
+
lg: "0.875rem"
|
|
330
|
+
},
|
|
331
|
+
spacing: {
|
|
332
|
+
xs: "0.25rem",
|
|
333
|
+
sm: "0.5rem",
|
|
334
|
+
md: "0.75rem",
|
|
335
|
+
lg: "1rem",
|
|
336
|
+
xl: "1.5rem"
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/theme/presets/dark.ts
|
|
341
|
+
var DARK_THEME = { tokens: {
|
|
342
|
+
...BASE_TOKENS,
|
|
343
|
+
colors: {
|
|
344
|
+
fg: "#ececf1",
|
|
345
|
+
fgMuted: "#a6a8b0",
|
|
346
|
+
bg: "#212121",
|
|
347
|
+
border: "#3c3e42",
|
|
348
|
+
accent: "#82b7ff",
|
|
349
|
+
accentHover: "#b1d2ff",
|
|
350
|
+
surfaceMuted: "#353639",
|
|
351
|
+
surfaceSubtle: "#292a2d",
|
|
352
|
+
borderEmphasis: "#666970"
|
|
353
|
+
},
|
|
354
|
+
syntax: {
|
|
355
|
+
comment: "#9da7b3",
|
|
356
|
+
keyword: "#ff7b72",
|
|
357
|
+
string: "#a5d6ff",
|
|
358
|
+
number: "#79c0ff",
|
|
359
|
+
function: "#d2a8ff",
|
|
360
|
+
variable: "#ffa657",
|
|
361
|
+
punctuation: "#c9d1d9",
|
|
362
|
+
inserted: "#7ee787",
|
|
363
|
+
deleted: "#ffa198"
|
|
364
|
+
}
|
|
365
|
+
} };
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/theme/presets/index.ts
|
|
368
|
+
var PRESET_THEME_MAP = {
|
|
369
|
+
light: { tokens: {
|
|
370
|
+
...BASE_TOKENS,
|
|
371
|
+
colors: {
|
|
372
|
+
fg: "#202123",
|
|
373
|
+
fgMuted: "#64676b",
|
|
374
|
+
bg: "#ffffff",
|
|
375
|
+
border: "#e5e7eb",
|
|
376
|
+
accent: "#0969da",
|
|
377
|
+
accentHover: "#0550ae",
|
|
378
|
+
surfaceMuted: "#f1f2f4",
|
|
379
|
+
surfaceSubtle: "#f7f8fa",
|
|
380
|
+
borderEmphasis: "#b5bac1"
|
|
381
|
+
},
|
|
382
|
+
syntax: {
|
|
383
|
+
comment: "#6e7781",
|
|
384
|
+
keyword: "#cf222e",
|
|
385
|
+
string: "#0a3069",
|
|
386
|
+
number: "#0550ae",
|
|
387
|
+
function: "#8250df",
|
|
388
|
+
variable: "#953800",
|
|
389
|
+
punctuation: "#57606a",
|
|
390
|
+
inserted: "#116329",
|
|
391
|
+
deleted: "#a40e26"
|
|
392
|
+
}
|
|
393
|
+
} },
|
|
394
|
+
dark: DARK_THEME
|
|
395
|
+
};
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/theme/utils.ts
|
|
398
|
+
var isThemeTuple = (theme) => isArray(theme);
|
|
399
|
+
var resolveTheme = (theme = "light") => {
|
|
400
|
+
if (isString(theme)) return PRESET_THEME_MAP[theme];
|
|
401
|
+
const [preset, overrides] = isThemeTuple(theme) ? theme : ["light", theme];
|
|
402
|
+
return merge({}, PRESET_THEME_MAP[preset], overrides);
|
|
403
|
+
};
|
|
404
|
+
var mapTokensToStyles = (tokens) => {
|
|
405
|
+
const styles = {};
|
|
406
|
+
const visit = (value, path) => {
|
|
407
|
+
forOwn(value, (token, key) => {
|
|
408
|
+
const name = `${path}-${replace(key, /[A-Z]/g, (letter) => `-${toLower(letter)}`)}`;
|
|
409
|
+
if (isObject(token)) visit(token, name);
|
|
410
|
+
else styles[name] = toString(token);
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
visit(tokens, `--${PREFIX}`);
|
|
414
|
+
return styles;
|
|
415
|
+
};
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/theme/consts.ts
|
|
418
|
+
var PRESET_STYLES = /*#__PURE__*/ mapValues(PRESET_THEME_MAP, ({ tokens }) => mapTokensToStyles(tokens));
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/theme/hooks.ts
|
|
421
|
+
var createThemeStyles = (theme = () => "light") => {
|
|
422
|
+
return createMemo(() => {
|
|
423
|
+
const value = theme();
|
|
424
|
+
return isString(value) ? PRESET_STYLES[value] : mapTokensToStyles(resolveTheme(value).tokens);
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/packs/utils/config.ts
|
|
429
|
+
var getTickerByType = (type) => {
|
|
430
|
+
if (!isString(type)) return type;
|
|
431
|
+
const ticker = ALL_TICKERS.find((item) => item.name === type);
|
|
432
|
+
assert(ticker, `Unknown ticker type: ${type}`);
|
|
433
|
+
return ticker;
|
|
434
|
+
};
|
|
435
|
+
var getSchedulerByType = (type) => {
|
|
436
|
+
if (!isString(type)) return type;
|
|
437
|
+
const scheduler = ALL_SCHEDULERS.find((item) => item.name === type);
|
|
438
|
+
assert(scheduler, `Unknown scheduler type: ${type}`);
|
|
439
|
+
return scheduler;
|
|
440
|
+
};
|
|
441
|
+
var toSmoothConfig = (config) => {
|
|
442
|
+
const { enabled = false, ticker, scheduler } = isBoolean(config) ? {
|
|
443
|
+
enabled: config,
|
|
444
|
+
ticker: isEnableRAF() ? "raf" : "interval",
|
|
445
|
+
scheduler: "spring"
|
|
446
|
+
} : config;
|
|
447
|
+
return {
|
|
448
|
+
enabled,
|
|
449
|
+
ticker: getTickerByType(ticker),
|
|
450
|
+
scheduler: getSchedulerByType(scheduler)
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
var toStreamingConfig = (config = false) => {
|
|
454
|
+
if (isBoolean(config)) return {
|
|
455
|
+
repairEnding: config,
|
|
456
|
+
smooth: config,
|
|
457
|
+
effect: config ? "scale" : false
|
|
458
|
+
};
|
|
459
|
+
const { repairEnding = true, smooth = true, effect = "scale" } = config;
|
|
460
|
+
return {
|
|
461
|
+
repairEnding,
|
|
462
|
+
smooth,
|
|
463
|
+
effect
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
var toBuildConfig = ({ base, repairEnding, idPrefix }) => {
|
|
467
|
+
return {
|
|
468
|
+
...defaultsBy(base, {
|
|
469
|
+
...DEFAULT_CONFIG,
|
|
470
|
+
idPrefix
|
|
471
|
+
}),
|
|
472
|
+
repairEnding
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/packs/utils/effect.ts
|
|
477
|
+
var toEffects = (effect = false) => {
|
|
478
|
+
if (effect === false) return [];
|
|
479
|
+
if (effect === true) return ["scale"];
|
|
480
|
+
if (!isArray(effect)) return [effect];
|
|
481
|
+
if (effect.length === 2 && !isArray(effect[1]) && isObjectLike(effect[1])) return [effect];
|
|
482
|
+
return effect;
|
|
483
|
+
};
|
|
484
|
+
var toEffectMappers = (effects, presets) => {
|
|
485
|
+
return effects.map((effect) => {
|
|
486
|
+
const [key, config] = isArray(effect) ? effect : [effect, EO];
|
|
487
|
+
if (!isString(key)) return effect;
|
|
488
|
+
const Mapper = presets.find((item) => item.key === key);
|
|
489
|
+
assert(Mapper, `Unknown effect: ${key}`);
|
|
490
|
+
return [Mapper, defaults({ ...config }, { enabled: true })];
|
|
491
|
+
});
|
|
492
|
+
};
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/packs/utils/patches.ts
|
|
495
|
+
var isPatchRangeEqual = (left, right) => {
|
|
496
|
+
return left === right || (isNumber(left) ? left : left[0]) === (isNumber(right) ? right : right[0]) && (isNumber(left) ? left : left[1]) === (isNumber(right) ? right : right[1]);
|
|
497
|
+
};
|
|
498
|
+
var isPatchesEqual = (left, right) => {
|
|
499
|
+
return left === right || left.length === right.length && left.every((patch, index) => {
|
|
500
|
+
const other = right[index];
|
|
501
|
+
return other !== void 0 && patch.key === other.key && isPatchRangeEqual(patch.range, other.range) && patch.render === other.render;
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region src/packs/raw/utils.ts
|
|
506
|
+
var mergeStyles = (theme, style) => {
|
|
507
|
+
if (!isString(style)) return {
|
|
508
|
+
...theme,
|
|
509
|
+
...style
|
|
510
|
+
};
|
|
511
|
+
return `${Object.entries(theme).map(([name, value]) => `${name}:${value}`).join(";")};${style}`;
|
|
512
|
+
};
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/packs/raw/index.tsx
|
|
515
|
+
var _tmpl$ = /*#__PURE__*/ template(`<div>`);
|
|
516
|
+
var FluxdownRaw = (props) => {
|
|
517
|
+
const [options, attributes] = splitProps(props, [
|
|
518
|
+
"text",
|
|
519
|
+
"build",
|
|
520
|
+
"streaming",
|
|
521
|
+
"patches",
|
|
522
|
+
"plugins",
|
|
523
|
+
"theme",
|
|
524
|
+
"class",
|
|
525
|
+
"style",
|
|
526
|
+
"ref"
|
|
527
|
+
]);
|
|
528
|
+
const streaming = createMemo(() => toStreamingConfig(options.streaming));
|
|
529
|
+
const effects = createMemo(() => toEffectMappers(toEffects(streaming().effect), PRESET_MAPPER_PLUGINS));
|
|
530
|
+
const idPrefix = createUniqueId();
|
|
531
|
+
const build = createStateOf(() => toBuildConfig({
|
|
532
|
+
base: options.build ?? EO,
|
|
533
|
+
repairEnding: streaming().repairEnding,
|
|
534
|
+
idPrefix
|
|
535
|
+
}), shallowEqual);
|
|
536
|
+
const patches = createStateOf(() => options.patches ?? EL, isPatchesEqual);
|
|
537
|
+
const text = createStateOf(() => options.text);
|
|
538
|
+
const plugins = createMemo(() => castArray(options.plugins));
|
|
539
|
+
const _remarks = createPlugins(plugins, "remarks");
|
|
540
|
+
const _rehypes = createPlugins(plugins, "rehypes");
|
|
541
|
+
const _repairs = createPlugins(plugins, "repairs");
|
|
542
|
+
const _mappers = createPlugins(plugins, "mappers");
|
|
543
|
+
const _renders = createPlugins(plugins, "renders");
|
|
544
|
+
const slots = createPlugins(plugins, "slots");
|
|
545
|
+
const remarks = createStateOf(_remarks, isPluggablesEqual);
|
|
546
|
+
const rehypes = createStateOf(_rehypes, isPluggablesEqual);
|
|
547
|
+
const repairs = createStateOf(_repairs, isPluggablesEqual);
|
|
548
|
+
const mappers = createStateOf(() => [[..._mappers(), ...effects()], { smooth: toSmoothConfig(streaming().smooth) }], isPluginSetEqual);
|
|
549
|
+
const renders = createStateOf(_renders, isPluggablesEqual);
|
|
550
|
+
const core = render(S([Core, {
|
|
551
|
+
Renderer: D(SolidRenderer),
|
|
552
|
+
build,
|
|
553
|
+
patches,
|
|
554
|
+
rehypes,
|
|
555
|
+
remarks,
|
|
556
|
+
renders,
|
|
557
|
+
repairs,
|
|
558
|
+
mappers,
|
|
559
|
+
text
|
|
560
|
+
}]));
|
|
561
|
+
const theme = createThemeStyles(() => options.theme ?? "light");
|
|
562
|
+
options.ref?.(core);
|
|
563
|
+
onCleanup(() => core.destroy());
|
|
564
|
+
return (() => {
|
|
565
|
+
var _el$ = getNextElement(_tmpl$);
|
|
566
|
+
spread(_el$, mergeProps(attributes, {
|
|
567
|
+
get ["class"]() {
|
|
568
|
+
return [
|
|
569
|
+
index_module_default.root,
|
|
570
|
+
ROOT_CLASS_NAME,
|
|
571
|
+
options.class
|
|
572
|
+
].filter(Boolean).join(" ");
|
|
573
|
+
},
|
|
574
|
+
get style() {
|
|
575
|
+
return mergeStyles(theme(), options.style);
|
|
576
|
+
}
|
|
577
|
+
}), false, true);
|
|
578
|
+
insert(_el$, createComponent(RenderProvider, {
|
|
579
|
+
value: { getProps: getSolidProps },
|
|
580
|
+
get children() {
|
|
581
|
+
return createComponent(SlotProvider, {
|
|
582
|
+
get plugins() {
|
|
583
|
+
return slots();
|
|
584
|
+
},
|
|
585
|
+
get children() {
|
|
586
|
+
return createComponent(RootReconciler, { get value() {
|
|
587
|
+
return core.value;
|
|
588
|
+
} });
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
}));
|
|
593
|
+
runHydrationEvents();
|
|
594
|
+
return _el$;
|
|
595
|
+
})();
|
|
596
|
+
};
|
|
597
|
+
//#endregion
|
|
598
|
+
export { createMergedPlugins as n, FluxdownRaw as t };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IRenderPatchItem } from '@fluxdown/core';
|
|
2
|
+
import type { ISolidRenderPlugin } from '@fluxdown/solid-plugins/base';
|
|
3
|
+
import type { GetPropsFunction } from '@fluxdown/solid-plugins/typings';
|
|
4
|
+
import type { IBlockState } from '@fluxdown/types';
|
|
5
|
+
import type { ElementContent, Parent, Root } from 'hast';
|
|
6
|
+
import type { JSX } from 'solid-js';
|
|
7
|
+
import type { IReactiveState, StateSource } from 'stative';
|
|
8
|
+
export interface BlockReconcilerProps {
|
|
9
|
+
block: IBlockState<Root>;
|
|
10
|
+
patches: StateSource<IRenderPatchItem<JSX.Element>[]>;
|
|
11
|
+
plugins: StateSource<ISolidRenderPlugin[]>;
|
|
12
|
+
}
|
|
13
|
+
export interface RenderNodeParams {
|
|
14
|
+
node: ElementContent | undefined;
|
|
15
|
+
parents: Parent[];
|
|
16
|
+
patches: IReactiveState<IRenderPatchItem<JSX.Element>[]>;
|
|
17
|
+
plugins: ISolidRenderPlugin[];
|
|
18
|
+
getProps: GetPropsFunction | undefined | null;
|
|
19
|
+
}
|
|
20
|
+
export interface RenderChildrenParams extends Omit<RenderNodeParams, 'node'> {
|
|
21
|
+
node: Parent | undefined;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ROOT_CLASS_NAME: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './render/index.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GetPropsFunction } from '@fluxdown/solid-plugins/typings';
|
|
2
|
+
export interface RenderConfig {
|
|
3
|
+
getProps?: GetPropsFunction | null;
|
|
4
|
+
}
|
|
5
|
+
export declare const RenderProvider: import("solid-js").ContextProviderComponent<RenderConfig | null>;
|
|
6
|
+
export declare const useRender: () => RenderConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/dist/esm/full.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { n as createMergedPlugins, t as FluxdownRaw } from "./chunks/raw-ULd4Y10B.js";
|
|
2
|
+
import { createComponent, mergeProps } from "solid-js/web";
|
|
3
|
+
import { PRESET_FULL_PLUGINS } from "@fluxdown/solid-plugins/full";
|
|
4
|
+
//#region src/packs/full/index.tsx
|
|
5
|
+
var Fluxdown = (props) => {
|
|
6
|
+
const plugins = createMergedPlugins(PRESET_FULL_PLUGINS, () => props.plugins);
|
|
7
|
+
return createComponent(FluxdownRaw, mergeProps(props, { get plugins() {
|
|
8
|
+
return plugins();
|
|
9
|
+
} }));
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Fluxdown };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './plugins.js';
|