-
Notifications
You must be signed in to change notification settings - Fork 382
/
api.ts
753 lines (698 loc) · 25 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
/*
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import {
APIFeature,
ArrayPush,
assert,
create as ObjectCreate,
forEach,
freeze as ObjectFreeze,
isAPIFeatureEnabled,
isArray,
isFalse,
isFunction,
isNull,
isNumber,
isObject,
isString,
isTrue,
isUndefined,
StringReplace,
toString,
} from '@lwc/shared';
import { logError } from '../shared/logger';
import { invokeEventListener } from './invoker';
import { getVMBeingRendered, setVMBeingRendered } from './template';
import { EmptyArray } from './utils';
import { isComponentConstructor } from './def';
import { RenderMode, ShadowMode, SlotSet, VM } from './vm';
import { LightningElementConstructor } from './base-lightning-element';
import { markAsDynamicChildren } from './rendering';
import {
isVBaseElement,
isVScopedSlotFragment,
isVStatic,
Key,
MutableVNodes,
VComment,
VCustomElement,
VElement,
VElementData,
VFragment,
VNode,
VNodes,
VNodeType,
VScopedSlotFragment,
VStatic,
VStaticPart,
VStaticPartData,
VStaticPartType,
VText,
} from './vnodes';
import { getComponentRegisteredName } from './component';
const SymbolIterator: typeof Symbol.iterator = Symbol.iterator;
function addVNodeToChildLWC(vnode: VCustomElement) {
ArrayPush.call(getVMBeingRendered()!.velements, vnode);
}
// [s]tatic [p]art
function sp(partId: number, data: VStaticPartData | null, text: string | null): VStaticPart {
// Static part will always have either text or data, it's guaranteed by the compiler.
const type = isNull(text) ? VStaticPartType.Element : VStaticPartType.Text;
return {
type,
partId,
data,
text,
elm: undefined, // elm is defined later
};
}
// [s]coped [s]lot [f]actory
function ssf(slotName: unknown, factory: (value: any, key: any) => VFragment): VScopedSlotFragment {
return {
type: VNodeType.ScopedSlotFragment,
factory,
owner: getVMBeingRendered()!,
elm: undefined,
sel: undefined,
key: undefined,
slotName,
};
}
// [st]atic node
function st(
fragmentFactory: (parts?: VStaticPart[]) => Element,
key: Key,
parts?: VStaticPart[]
): VStatic {
const owner = getVMBeingRendered()!;
const fragment = fragmentFactory(parts);
const vnode: VStatic = {
type: VNodeType.Static,
sel: undefined,
key,
elm: undefined,
fragment,
owner,
parts,
slotAssignment: undefined,
};
return vnode;
}
// [fr]agment node
function fr(key: Key, children: VNodes, stable: 0 | 1): VFragment {
const owner = getVMBeingRendered()!;
const useCommentNodes = isAPIFeatureEnabled(
APIFeature.USE_COMMENTS_FOR_FRAGMENT_BOOKENDS,
owner.apiVersion
);
const leading = useCommentNodes ? co('') : t('');
const trailing = useCommentNodes ? co('') : t('');
return {
type: VNodeType.Fragment,
sel: undefined,
key,
elm: undefined,
children: [leading, ...children, trailing],
stable,
owner,
leading,
trailing,
};
}
// [h]tml node
function h(sel: string, data: VElementData, children: VNodes = EmptyArray): VElement {
const vmBeingRendered = getVMBeingRendered()!;
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isString(sel), `h() 1st argument sel must be a string.`);
assert.isTrue(isObject(data), `h() 2nd argument data must be an object.`);
assert.isTrue(isArray(children), `h() 3rd argument children must be an array.`);
assert.isTrue(
'key' in data,
` <${sel}> "key" attribute is invalid or missing for ${vmBeingRendered}. Key inside iterator is either undefined or null.`
);
// checking reserved internal data properties
assert.isFalse(
data.className && data.classMap,
`vnode.data.className and vnode.data.classMap ambiguous declaration.`
);
assert.isFalse(
data.styleDecls && data.style,
`vnode.data.styleDecls and vnode.data.style ambiguous declaration.`
);
forEach.call(children, (childVnode: VNode | null | undefined) => {
if (childVnode != null) {
assert.isTrue(
'type' in childVnode &&
'sel' in childVnode &&
'elm' in childVnode &&
'key' in childVnode,
`${childVnode} is not a vnode.`
);
}
});
}
const { key, slotAssignment } = data;
const vnode: VElement = {
type: VNodeType.Element,
sel,
data,
children,
elm: undefined,
key,
owner: vmBeingRendered,
slotAssignment,
};
return vnode;
}
// [t]ab[i]ndex function
function ti(value: any): number {
// if value is greater than 0, we normalize to 0
// If value is an invalid tabIndex value (null, undefined, string, etc), we let that value pass through
// If value is less than -1, we don't care
const shouldNormalize = value > 0 && !(isTrue(value) || isFalse(value));
if (process.env.NODE_ENV !== 'production') {
const vmBeingRendered = getVMBeingRendered();
if (shouldNormalize) {
logError(
`Invalid tabindex value \`${toString(
value
)}\` in template for ${vmBeingRendered}. This attribute must be set to 0 or -1.`,
vmBeingRendered!
);
}
}
return shouldNormalize ? 0 : value;
}
// [s]lot element node
function s(
slotName: string,
data: VElementData,
children: VNodes,
slotset: SlotSet | undefined
): VElement | VNodes | VFragment {
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isString(slotName), `s() 1st argument slotName must be a string.`);
assert.isTrue(isObject(data), `s() 2nd argument data must be an object.`);
assert.isTrue(isArray(children), `h() 3rd argument children must be an array.`);
}
const vmBeingRendered = getVMBeingRendered()!;
const { renderMode, apiVersion } = vmBeingRendered;
if (
!isUndefined(slotset) &&
!isUndefined(slotset.slotAssignments) &&
!isUndefined(slotset.slotAssignments[slotName]) &&
slotset.slotAssignments[slotName].length !== 0
) {
const newChildren: VNode[] = [];
const slotAssignments = slotset.slotAssignments[slotName];
for (let i = 0; i < slotAssignments.length; i++) {
const vnode = slotAssignments[i];
if (!isNull(vnode)) {
const assignedNodeIsScopedSlot = isVScopedSlotFragment(vnode);
// The only sniff test for a scoped <slot> element is the presence of `slotData`
const isScopedSlotElement = !isUndefined(data.slotData);
// Check if slot types of parent and child are matching
if (assignedNodeIsScopedSlot !== isScopedSlotElement) {
if (process.env.NODE_ENV !== 'production') {
logError(
`Mismatched slot types for ${
slotName === '' ? '(default)' : slotName
} slot. Both parent and child component must use standard type or scoped type for a given slot.`,
slotset.owner
);
}
// Ignore slot content from parent
continue;
}
// If the passed slot content is factory, evaluate it and add the produced vnodes
if (assignedNodeIsScopedSlot) {
// Evaluate in the scope of the slot content's owner
// if a slotset is provided, there will always be an owner. The only case where owner is
// undefined is for root components, but root components cannot accept slotted content
setVMBeingRendered(slotset.owner!);
try {
// The factory function is a template snippet from the slot set owner's template,
// hence switch over to the slot set owner's template reactive observer
const { tro } = slotset.owner!;
tro.observe(() => {
ArrayPush.call(newChildren, vnode.factory(data.slotData, data.key));
});
} finally {
setVMBeingRendered(vmBeingRendered);
}
} else {
// This block is for standard slots (non-scoped slots)
let clonedVNode;
if (
renderMode === RenderMode.Light &&
isAPIFeatureEnabled(APIFeature.USE_LIGHT_DOM_SLOT_FORWARDING, apiVersion) &&
(isVBaseElement(vnode) || isVStatic(vnode)) &&
// We only need to copy the vnodes when the slot assignment changes, copying every time causes issues with
// disconnected/connected callback firing.
vnode.slotAssignment !== data.slotAssignment
) {
// When the light DOM slot assignment (slot attribute) changes we can't use the same reference
// to the vnode because the current way the diffing algo works, it will replace the original reference
// to the host element with a new one. This means the new element will be mounted and immediately unmounted.
// Creating a copy of the vnode to preserve a reference to the previous host element.
clonedVNode = { ...vnode, slotAssignment: data.slotAssignment };
}
// If the slot content is standard type, the content is static, no additional
// processing needed on the vnode
ArrayPush.call(newChildren, clonedVNode ?? vnode);
}
}
}
children = newChildren;
}
const { shadowMode } = vmBeingRendered;
if (renderMode === RenderMode.Light) {
// light DOM slots - backwards-compatible behavior uses flattening, new behavior uses fragments
if (isAPIFeatureEnabled(APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS, apiVersion)) {
return fr(data.key, children, 0);
} else {
sc(children);
return children;
}
}
if (shadowMode === ShadowMode.Synthetic) {
// TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
sc(children);
}
return h('slot', data, children);
}
// [c]ustom element node
function c(
sel: string,
Ctor: LightningElementConstructor,
data: VElementData,
children: VNodes = EmptyArray
): VCustomElement {
const vmBeingRendered = getVMBeingRendered()!;
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isString(sel), `c() 1st argument sel must be a string.`);
assert.isTrue(isFunction(Ctor), `c() 2nd argument Ctor must be a function.`);
assert.isTrue(isObject(data), `c() 3nd argument data must be an object.`);
assert.isTrue(
arguments.length === 3 || isArray(children),
`c() 4nd argument data must be an array.`
);
// checking reserved internal data properties
assert.isFalse(
data.className && data.classMap,
`vnode.data.className and vnode.data.classMap ambiguous declaration.`
);
assert.isFalse(
data.styleDecls && data.style,
`vnode.data.styleDecls and vnode.data.style ambiguous declaration.`
);
if (data.style && !isString(data.style)) {
logError(
`Invalid 'style' attribute passed to <${sel}> is ignored. This attribute must be a string value.`,
vmBeingRendered
);
}
if (arguments.length === 4) {
forEach.call(children, (childVnode: VNode | null | undefined) => {
if (childVnode != null) {
assert.isTrue(
'type' in childVnode &&
'sel' in childVnode &&
'elm' in childVnode &&
'key' in childVnode,
`${childVnode} is not a vnode.`
);
}
});
}
}
const { key, slotAssignment } = data;
let elm, aChildren, vm;
const vnode: VCustomElement = {
type: VNodeType.CustomElement,
sel,
data,
children,
elm,
key,
slotAssignment,
ctor: Ctor,
owner: vmBeingRendered,
mode: 'open', // TODO [#1294]: this should be defined in Ctor
aChildren,
vm,
};
addVNodeToChildLWC(vnode);
return vnode;
}
// [i]terable node
function i(
iterable: Iterable<any>,
factory: (value: any, index: number, first: boolean, last: boolean) => VNodes | VNode
): VNodes {
const list: MutableVNodes = [];
// TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
sc(list);
const vmBeingRendered = getVMBeingRendered()!;
if (isUndefined(iterable) || iterable === null) {
if (process.env.NODE_ENV !== 'production') {
logError(
`Invalid template iteration for value "${toString(
iterable
)}" in ${vmBeingRendered}. It must be an Array or an iterable Object.`,
vmBeingRendered!
);
}
return list;
}
if (process.env.NODE_ENV !== 'production') {
assert.isFalse(
isUndefined(iterable[SymbolIterator]),
`Invalid template iteration for value \`${toString(
iterable
)}\` in ${vmBeingRendered}. It must be an array-like object and not \`null\` nor \`undefined\`.`
);
}
const iterator = iterable[SymbolIterator]();
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(
iterator && isFunction(iterator.next),
`Invalid iterator function for "${toString(iterable)}" in ${vmBeingRendered}.`
);
}
let next = iterator.next();
let j = 0;
let { value, done: last } = next;
let keyMap: Record<string, number>;
let iterationError: string | undefined;
if (process.env.NODE_ENV !== 'production') {
keyMap = ObjectCreate(null);
}
while (last === false) {
// implementing a look-back-approach because we need to know if the element is the last
next = iterator.next();
last = next.done;
// template factory logic based on the previous collected value
const vnode = factory(value, j, j === 0, last === true);
if (isArray(vnode)) {
ArrayPush.apply(list, vnode);
} else {
// `isArray` doesn't narrow this block properly...
ArrayPush.call(list, vnode as VNode | null);
}
if (process.env.NODE_ENV !== 'production') {
const vnodes = isArray(vnode) ? vnode : [vnode];
forEach.call(vnodes, (childVnode: VNode | null) => {
// Check that the child vnode is either an element or VStatic
if (!isNull(childVnode) && (isVBaseElement(childVnode) || isVStatic(childVnode))) {
const { key } = childVnode;
// In @lwc/engine-server the fragment doesn't have a tagName, default to the VM's tagName.
const { tagName } = vmBeingRendered;
if (isString(key) || isNumber(key)) {
if (keyMap[key] === 1 && isUndefined(iterationError)) {
iterationError = `Duplicated "key" attribute value in "<${tagName}>" for item number ${j}. A key with value "${key}" appears more than once in the iteration. Key values must be unique numbers or strings.`;
}
keyMap[key] = 1;
} else if (isUndefined(iterationError)) {
iterationError = `Invalid "key" attribute value in "<${tagName}>" for item number ${j}. Set a unique "key" value on all iterated child elements.`;
}
}
});
}
// preparing next value
j += 1;
value = next.value;
}
if (process.env.NODE_ENV !== 'production') {
if (!isUndefined(iterationError)) {
logError(iterationError, vmBeingRendered!);
}
}
return list;
}
/**
* [f]lattening
* @param items
*/
function f(items: ReadonlyArray<VNodes> | VNodes): VNodes {
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isArray(items), 'flattening api can only work with arrays.');
}
const len = items.length;
const flattened: MutableVNodes = [];
// TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
sc(flattened);
for (let j = 0; j < len; j += 1) {
const item = items[j];
if (isArray(item)) {
ArrayPush.apply(flattened, item);
} else {
// `isArray` doesn't narrow this block properly...
ArrayPush.call(flattened, item as VNode | null);
}
}
return flattened;
}
// [t]ext node
function t(text: string): VText {
let sel, key, elm;
return {
type: VNodeType.Text,
sel,
text,
elm,
key,
owner: getVMBeingRendered()!,
};
}
// [co]mment node
function co(text: string): VComment {
let sel, elm;
return {
type: VNodeType.Comment,
sel,
text,
elm,
key: 'c',
owner: getVMBeingRendered()!,
};
}
// [d]ynamic text
function d(value: any): string {
return value == null ? '' : String(value);
}
// [b]ind function
function b(fn: EventListener): EventListener {
const vmBeingRendered = getVMBeingRendered();
if (isNull(vmBeingRendered)) {
throw new Error();
}
const vm: VM = vmBeingRendered;
return function (event: Event) {
invokeEventListener(vm, fn, vm.component, event);
};
}
// [k]ey function
function k(compilerKey: number, obj: any): string | void {
switch (typeof obj) {
case 'number':
case 'string':
return compilerKey + ':' + obj;
case 'object':
if (process.env.NODE_ENV !== 'production') {
logError(
`Invalid key value "${obj}" in ${getVMBeingRendered()}. Key must be a string or number.`
);
}
}
}
// [g]lobal [id] function
function gid(id: string | undefined | null): string | null | undefined {
const vmBeingRendered = getVMBeingRendered()!;
if (isUndefined(id) || id === '') {
if (process.env.NODE_ENV !== 'production') {
logError(
`Invalid id value "${id}". The id attribute must contain a non-empty string.`,
vmBeingRendered
);
}
return id;
}
// We remove attributes when they are assigned a value of null
if (isNull(id)) {
return null;
}
const { idx, shadowMode } = vmBeingRendered;
if (shadowMode === ShadowMode.Synthetic) {
return StringReplace.call(id, /\S+/g, (id) => `${id}-${idx}`);
}
return id;
}
// [f]ragment [id] function
function fid(url: string | undefined | null): string | null | undefined {
const vmBeingRendered = getVMBeingRendered()!;
if (isUndefined(url) || url === '') {
if (process.env.NODE_ENV !== 'production') {
if (isUndefined(url)) {
logError(
`Undefined url value for "href" or "xlink:href" attribute. Expected a non-empty string.`,
vmBeingRendered
);
}
}
return url;
}
// We remove attributes when they are assigned a value of null
if (isNull(url)) {
return null;
}
const { idx, shadowMode } = vmBeingRendered;
// Apply transformation only for fragment-only-urls, and only in shadow DOM
if (shadowMode === ShadowMode.Synthetic && /^#/.test(url)) {
return `${url}-${idx}`;
}
return url;
}
/**
* [ddc] - create a (deprecated) dynamic component via `<x-foo lwc:dynamic={Ctor}>`
*
* TODO [#3331]: remove usage of lwc:dynamic in 246
* @param sel
* @param Ctor
* @param data
* @param children
*/
function ddc(
sel: string,
Ctor: LightningElementConstructor | null | undefined,
data: VElementData,
children: VNodes = EmptyArray
): VCustomElement | null {
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isString(sel), `dc() 1st argument sel must be a string.`);
assert.isTrue(isObject(data), `dc() 3nd argument data must be an object.`);
assert.isTrue(
arguments.length === 3 || isArray(children),
`dc() 4nd argument data must be an array.`
);
}
// null or undefined values should produce a null value in the VNodes
if (isNull(Ctor) || isUndefined(Ctor)) {
return null;
}
if (!isComponentConstructor(Ctor)) {
throw new Error(`Invalid LWC Constructor ${toString(Ctor)} for custom element <${sel}>.`);
}
return c(sel, Ctor, data, children);
}
/**
* [dc] - create a dynamic component via `<lwc:component lwc:is={Ctor}>`
* @param Ctor
* @param data
* @param children
*/
function dc(
Ctor: LightningElementConstructor | null | undefined,
data: VElementData,
children: VNodes = EmptyArray
): VCustomElement | null {
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isObject(data), `dc() 2nd argument data must be an object.`);
assert.isTrue(
arguments.length === 3 || isArray(children),
`dc() 3rd argument data must be an array.`
);
}
// Null or undefined values should produce a null value in the VNodes.
// This is the only value at compile time as the constructor will not be known.
if (isNull(Ctor) || isUndefined(Ctor)) {
return null;
}
if (!isComponentConstructor(Ctor)) {
throw new Error(
`Invalid constructor ${toString(Ctor)} is not a LightningElement constructor.`
);
}
// Look up the dynamic component's name at runtime once the constructor is available.
// This information is only known at runtime and is stored as part of registerComponent.
const sel = getComponentRegisteredName(Ctor);
if (isUndefined(sel) || sel === '') {
throw new Error(
`Invalid LWC constructor ${toString(Ctor)} does not have a registered name`
);
}
return c(sel, Ctor, data, children);
}
/**
* slow children collection marking mechanism. this API allows the compiler to signal
* to the engine that a particular collection of children must be diffed using the slow
* algo based on keys due to the nature of the list. E.g.:
*
* - slot element's children: the content of the slot has to be dynamic when in synthetic
* shadow mode because the `vnode.children` might be the slotted
* content vs default content, in which case the size and the
* keys are not matching.
* - children that contain dynamic components
* - children that are produced by iteration
* @param vnodes
*/
function sc(vnodes: VNodes): VNodes {
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isArray(vnodes), 'sc() api can only work with arrays.');
}
// We have to mark the vnodes collection as dynamic so we can later on
// choose to use the snabbdom virtual dom diffing algo instead of our
// static dummy algo.
markAsDynamicChildren(vnodes);
return vnodes;
}
/**
* EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
* libraries to sanitize HTML content. This hook process the content passed via the template to
* lwc:inner-html directive.
* It is meant to be overridden with setSanitizeHtmlContentHook, it throws an error by default.
*/
let sanitizeHtmlContentHook: SanitizeHtmlContentHook = (): string => {
// locker-service patches this function during runtime to sanitize HTML content.
throw new Error('sanitizeHtmlContent hook must be implemented.');
};
export type SanitizeHtmlContentHook = (content: unknown) => string;
/**
* Sets the sanitizeHtmlContentHook.
* @param newHookImpl
*/
export function setSanitizeHtmlContentHook(newHookImpl: SanitizeHtmlContentHook) {
sanitizeHtmlContentHook = newHookImpl;
}
// [s]anitize [h]tml [c]ontent
function shc(content: unknown): string {
return sanitizeHtmlContentHook(content);
}
const api = ObjectFreeze({
s,
h,
c,
i,
f,
t,
d,
b,
k,
co,
dc,
fr,
ti,
st,
gid,
fid,
shc,
ssf,
ddc,
sp,
});
export default api;
export type RenderAPI = typeof api;