frosty 0.0.93 → 0.0.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,137 +1,12 @@
1
1
  import _ from 'lodash';
2
- import { myersSync } from 'myers.js';
3
- import { N as NativeElementType } from './component-BzurKp_J.mjs';
4
2
  import { _ as _Renderer } from './renderer-C3Lq-xHV.mjs';
5
3
  import postcss from 'postcss';
6
4
  import { parse } from 'postcss-js';
7
5
  import nested from 'postcss-nested';
8
6
  import autoprefixer from 'autoprefixer';
9
7
  import { a as uniqueId, m as mergeRefs } from './state-BRL-17Kd.mjs';
10
-
11
- //
12
- // event.ts
13
- //
14
- // The MIT License
15
- // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
16
- //
17
- // Permission is hereby granted, free of charge, to any person obtaining a copy
18
- // of this software and associated documentation files (the "Software"), to deal
19
- // in the Software without restriction, including without limitation the rights
20
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
- // copies of the Software, and to permit persons to whom the Software is
22
- // furnished to do so, subject to the following conditions:
23
- //
24
- // The above copyright notice and this permission notice shall be included in
25
- // all copies or substantial portions of the Software.
26
- //
27
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33
- // THE SOFTWARE.
34
- //
35
- const globalEvents = [
36
- // Clipboard Events
37
- "onCopy",
38
- "onCut",
39
- "onPaste",
40
- // Composition Events
41
- "onCompositionEnd",
42
- "onCompositionStart",
43
- "onCompositionUpdate",
44
- // Focus Events
45
- "onFocus",
46
- "onBlur",
47
- // Form Events
48
- "onFormData",
49
- "onChange",
50
- "onBeforeInput",
51
- "onInput",
52
- "onReset",
53
- "onSubmit",
54
- "onInvalid",
55
- // Image Events
56
- "onLoad",
57
- "onError",
58
- // Keyboard Events
59
- "onKeyDown",
60
- /** @deprecated */
61
- "onKeyPress",
62
- /** @deprecated */
63
- "onKeyUp",
64
- // Media Events
65
- "onAbort",
66
- "onCanPlay",
67
- "onCanPlayThrough",
68
- "onDurationChange",
69
- "onEmptied",
70
- "onEncrypted",
71
- "onEnded",
72
- "onLoadedData",
73
- "onLoadedMetadata",
74
- "onLoadStart",
75
- "onPause",
76
- "onPlay",
77
- "onPlaying",
78
- "onProgress",
79
- "onRateChange",
80
- "onResize",
81
- "onSeeked",
82
- "onSeeking",
83
- "onStalled",
84
- "onSuspend",
85
- "onTimeUpdate",
86
- "onVolumeChange",
87
- "onWaiting",
88
- // MouseEvents
89
- "onAuxClick",
90
- "onClick",
91
- "onContextMenu",
92
- "onDoubleClick",
93
- "onDrag",
94
- "onDragEnd",
95
- "onDragEnter",
96
- "onDragExit",
97
- "onDragLeave",
98
- "onDragOver",
99
- "onDragStart",
100
- "onDrop",
101
- "onMouseDown",
102
- "onMouseEnter",
103
- "onMouseLeave",
104
- "onMouseMove",
105
- "onMouseOut",
106
- "onMouseOver",
107
- "onMouseUp",
108
- // Selection Events
109
- "onSelect",
110
- // Touch Events
111
- "onTouchCancel",
112
- "onTouchEnd",
113
- "onTouchMove",
114
- "onTouchStart",
115
- // Pointer Events
116
- "onPointerDown",
117
- "onPointerMove",
118
- "onPointerUp",
119
- "onPointerCancel",
120
- "onPointerEnter",
121
- "onPointerLeave",
122
- "onPointerOver",
123
- "onPointerOut",
124
- // UI Events
125
- "onScroll",
126
- // Wheel Events
127
- "onWheel",
128
- // Animation Events
129
- "onAnimationStart",
130
- "onAnimationEnd",
131
- "onAnimationIteration",
132
- // Transition Events
133
- "onTransitionEnd",
134
- ];
8
+ import { myersSync } from 'myers.js';
9
+ import { N as NativeElementType } from './component-BzurKp_J.mjs';
135
10
 
136
11
  const svgProps = {
137
12
  "*": {
@@ -3672,57 +3547,6 @@ const tags = {
3672
3547
  ]
3673
3548
  };
3674
3549
 
3675
- //
3676
- // props.ts
3677
- //
3678
- // The MIT License
3679
- // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
3680
- //
3681
- // Permission is hereby granted, free of charge, to any person obtaining a copy
3682
- // of this software and associated documentation files (the "Software"), to deal
3683
- // in the Software without restriction, including without limitation the rights
3684
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3685
- // copies of the Software, and to permit persons to whom the Software is
3686
- // furnished to do so, subject to the following conditions:
3687
- //
3688
- // The above copyright notice and this permission notice shall be included in
3689
- // all copies or substantial portions of the Software.
3690
- //
3691
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3692
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3693
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3694
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3695
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3696
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3697
- // THE SOFTWARE.
3698
- //
3699
- const _propValue = {
3700
- 'DOMString': 'string',
3701
- 'SVGAnimatedTransformList': 'string',
3702
- 'SVGStringList': 'string',
3703
- 'SVGAnimatedRect': 'string',
3704
- 'SVGAnimatedPreserveAspectRatio': 'string',
3705
- 'SVGAnimatedString': 'string',
3706
- 'SVGPointList': 'string',
3707
- 'SVGAnimatedLengthList': 'string',
3708
- 'SVGAnimatedNumberList': 'string',
3709
- 'SVGAnimatedEnumeration': 'string',
3710
- 'USVString': 'string',
3711
- 'DOMTokenList': 'string',
3712
- 'TrustedHTML': 'string',
3713
- 'HTMLFormElement': 'string',
3714
- 'HTMLDataListElement': 'string',
3715
- 'SVGAnimatedLength': 'length',
3716
- 'SVGAnimatedNumber': 'number',
3717
- 'SVGAnimatedInteger': 'number',
3718
- 'unrestricted double': 'number',
3719
- 'double': 'number',
3720
- 'unsigned long': 'number',
3721
- 'long': 'number',
3722
- 'SVGAnimatedBoolean': 'boolean',
3723
- 'boolean': 'boolean',
3724
- };
3725
-
3726
3550
  //
3727
3551
  // process.ts
3728
3552
  //
@@ -3930,7 +3754,7 @@ const altAlpha = ":;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx
3930
3754
  const compress = (r) => _compress(r, 6, r => altAlpha.charAt(r));
3931
3755
 
3932
3756
  //
3933
- // common.ts
3757
+ // event.ts
3934
3758
  //
3935
3759
  // The MIT License
3936
3760
  // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
@@ -3953,82 +3777,403 @@ const compress = (r) => _compress(r, 6, r => altAlpha.charAt(r));
3953
3777
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3954
3778
  // THE SOFTWARE.
3955
3779
  //
3956
- const SVG_NS = 'http://www.w3.org/2000/svg';
3957
- const HTML_NS = 'http://www.w3.org/1999/xhtml';
3958
- const MATHML_NS = 'http://www.w3.org/1998/Math/MathML';
3959
- const findPrototypeProperty = (object, propertyName) => {
3960
- while (object && object.constructor && object.constructor.name !== 'Object') {
3961
- let desc = Object.getOwnPropertyDescriptor(object, propertyName);
3962
- if (desc)
3963
- return desc;
3964
- object = Object.getPrototypeOf(object);
3965
- }
3966
- return null;
3967
- };
3968
- const isWriteable = (object, propertyName) => {
3969
- let desc = findPrototypeProperty(object, propertyName);
3970
- if (!desc) {
3971
- return false;
3972
- }
3973
- if (desc.writable && typeof desc.value !== 'function') {
3974
- return true;
3975
- }
3976
- return !!desc.set;
3977
- };
3978
- class DOMNativeNode extends NativeElementType {
3979
- static createElement;
3980
- }
3981
- class _DOMRenderer extends _Renderer {
3982
- _window;
3983
- _namespace_map = new WeakMap();
3984
- _tracked_head_children = [];
3985
- _tracked_style = new StyleBuilder();
3986
- /** @internal */
3987
- _tracked_server_resource = new Map();
3988
- _tracked_elements = new Map();
3989
- constructor(window) {
3990
- super();
3991
- this._window = window;
3992
- }
3993
- get document() {
3994
- return this.window.document;
3995
- }
3996
- get window() {
3997
- return this._window;
3998
- }
3999
- /** @internal */
4000
- _beforeUpdate() {
4001
- if (this._server) {
4002
- this._tracked_head_children = [];
4003
- this._tracked_server_resource = new Map();
4004
- }
4005
- }
4006
- /** @internal */
4007
- _afterUpdate() {
4008
- this._tracked_style.select([...this._tracked_elements.values().flatMap(({ className }) => className)]);
4009
- const head = this.document.head ?? this.document.createElementNS(HTML_NS, 'head');
4010
- const styleElem = this.document.querySelector('style[data-frosty-style]') ?? this.document.createElementNS(HTML_NS, 'style');
4011
- styleElem.setAttribute('data-frosty-style', '');
4012
- if (styleElem.textContent !== this._tracked_style.css)
4013
- styleElem.textContent = this._tracked_style.css;
4014
- if (this._server) {
4015
- const ssrData = this._tracked_server_resource.size ? this.document.createElementNS(HTML_NS, 'script') : undefined;
4016
- if (ssrData) {
4017
- ssrData.setAttribute('data-frosty-ssr-data', '');
4018
- ssrData.setAttribute('type', 'text/plain');
4019
- ssrData.innerHTML = compress(JSON.stringify(Object.fromEntries(this._tracked_server_resource)));
4020
- }
4021
- this.__replaceChildren(head, _.compact([
4022
- ...this._tracked_head_children,
4023
- styleElem.textContent && styleElem,
4024
- ssrData,
4025
- ]));
4026
- }
4027
- else if (styleElem.parentNode !== head && styleElem.textContent) {
4028
- head.appendChild(styleElem);
4029
- }
4030
- if (!this.document.head) {
4031
- this.document.documentElement.insertBefore(head, this.document.body);
3780
+ const globalEvents = [
3781
+ // Clipboard Events
3782
+ "onCopy",
3783
+ "onCut",
3784
+ "onPaste",
3785
+ // Composition Events
3786
+ "onCompositionEnd",
3787
+ "onCompositionStart",
3788
+ "onCompositionUpdate",
3789
+ // Focus Events
3790
+ "onFocus",
3791
+ "onBlur",
3792
+ // Form Events
3793
+ "onFormData",
3794
+ "onChange",
3795
+ "onBeforeInput",
3796
+ "onInput",
3797
+ "onReset",
3798
+ "onSubmit",
3799
+ "onInvalid",
3800
+ // Image Events
3801
+ "onLoad",
3802
+ "onError",
3803
+ // Keyboard Events
3804
+ "onKeyDown",
3805
+ /** @deprecated */
3806
+ "onKeyPress",
3807
+ /** @deprecated */
3808
+ "onKeyUp",
3809
+ // Media Events
3810
+ "onAbort",
3811
+ "onCanPlay",
3812
+ "onCanPlayThrough",
3813
+ "onDurationChange",
3814
+ "onEmptied",
3815
+ "onEncrypted",
3816
+ "onEnded",
3817
+ "onLoadedData",
3818
+ "onLoadedMetadata",
3819
+ "onLoadStart",
3820
+ "onPause",
3821
+ "onPlay",
3822
+ "onPlaying",
3823
+ "onProgress",
3824
+ "onRateChange",
3825
+ "onResize",
3826
+ "onSeeked",
3827
+ "onSeeking",
3828
+ "onStalled",
3829
+ "onSuspend",
3830
+ "onTimeUpdate",
3831
+ "onVolumeChange",
3832
+ "onWaiting",
3833
+ // MouseEvents
3834
+ "onAuxClick",
3835
+ "onClick",
3836
+ "onContextMenu",
3837
+ "onDoubleClick",
3838
+ "onDrag",
3839
+ "onDragEnd",
3840
+ "onDragEnter",
3841
+ "onDragExit",
3842
+ "onDragLeave",
3843
+ "onDragOver",
3844
+ "onDragStart",
3845
+ "onDrop",
3846
+ "onMouseDown",
3847
+ "onMouseEnter",
3848
+ "onMouseLeave",
3849
+ "onMouseMove",
3850
+ "onMouseOut",
3851
+ "onMouseOver",
3852
+ "onMouseUp",
3853
+ // Selection Events
3854
+ "onSelect",
3855
+ // Touch Events
3856
+ "onTouchCancel",
3857
+ "onTouchEnd",
3858
+ "onTouchMove",
3859
+ "onTouchStart",
3860
+ // Pointer Events
3861
+ "onPointerDown",
3862
+ "onPointerMove",
3863
+ "onPointerUp",
3864
+ "onPointerCancel",
3865
+ "onPointerEnter",
3866
+ "onPointerLeave",
3867
+ "onPointerOver",
3868
+ "onPointerOut",
3869
+ // UI Events
3870
+ "onScroll",
3871
+ // Wheel Events
3872
+ "onWheel",
3873
+ // Animation Events
3874
+ "onAnimationStart",
3875
+ "onAnimationEnd",
3876
+ "onAnimationIteration",
3877
+ // Transition Events
3878
+ "onTransitionEnd",
3879
+ ];
3880
+
3881
+ //
3882
+ // props.ts
3883
+ //
3884
+ // The MIT License
3885
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
3886
+ //
3887
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
3888
+ // of this software and associated documentation files (the "Software"), to deal
3889
+ // in the Software without restriction, including without limitation the rights
3890
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3891
+ // copies of the Software, and to permit persons to whom the Software is
3892
+ // furnished to do so, subject to the following conditions:
3893
+ //
3894
+ // The above copyright notice and this permission notice shall be included in
3895
+ // all copies or substantial portions of the Software.
3896
+ //
3897
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3898
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3899
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3900
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3901
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3902
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3903
+ // THE SOFTWARE.
3904
+ //
3905
+ const _propValue = {
3906
+ 'DOMString': 'string',
3907
+ 'SVGAnimatedTransformList': 'string',
3908
+ 'SVGStringList': 'string',
3909
+ 'SVGAnimatedRect': 'string',
3910
+ 'SVGAnimatedPreserveAspectRatio': 'string',
3911
+ 'SVGAnimatedString': 'string',
3912
+ 'SVGPointList': 'string',
3913
+ 'SVGAnimatedLengthList': 'string',
3914
+ 'SVGAnimatedNumberList': 'string',
3915
+ 'SVGAnimatedEnumeration': 'string',
3916
+ 'USVString': 'string',
3917
+ 'DOMTokenList': 'string',
3918
+ 'TrustedHTML': 'string',
3919
+ 'HTMLFormElement': 'string',
3920
+ 'HTMLDataListElement': 'string',
3921
+ 'SVGAnimatedLength': 'length',
3922
+ 'SVGAnimatedNumber': 'number',
3923
+ 'SVGAnimatedInteger': 'number',
3924
+ 'unrestricted double': 'number',
3925
+ 'double': 'number',
3926
+ 'unsigned long': 'number',
3927
+ 'long': 'number',
3928
+ 'SVGAnimatedBoolean': 'boolean',
3929
+ 'boolean': 'boolean',
3930
+ };
3931
+
3932
+ //
3933
+ // common.ts
3934
+ //
3935
+ // The MIT License
3936
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
3937
+ //
3938
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
3939
+ // of this software and associated documentation files (the "Software"), to deal
3940
+ // in the Software without restriction, including without limitation the rights
3941
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3942
+ // copies of the Software, and to permit persons to whom the Software is
3943
+ // furnished to do so, subject to the following conditions:
3944
+ //
3945
+ // The above copyright notice and this permission notice shall be included in
3946
+ // all copies or substantial portions of the Software.
3947
+ //
3948
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3949
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3950
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3951
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3952
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3953
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3954
+ // THE SOFTWARE.
3955
+ //
3956
+ const findPrototypeProperty = (object, propertyName) => {
3957
+ while (object && object.constructor && object.constructor.name !== 'Object') {
3958
+ let desc = Object.getOwnPropertyDescriptor(object, propertyName);
3959
+ if (desc)
3960
+ return desc;
3961
+ object = Object.getPrototypeOf(object);
3962
+ }
3963
+ return null;
3964
+ };
3965
+ const isWriteable = (object, propertyName) => {
3966
+ let desc = findPrototypeProperty(object, propertyName);
3967
+ if (!desc) {
3968
+ return false;
3969
+ }
3970
+ if (desc.writable && typeof desc.value !== 'function') {
3971
+ return true;
3972
+ }
3973
+ return !!desc.set;
3974
+ };
3975
+ const tracked_listeners = new WeakMap();
3976
+ const _updateEventListener = (element, key, listener) => {
3977
+ const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();
3978
+ const listeners = tracked_listeners.get(element) ?? {};
3979
+ if (!tracked_listeners.has(element))
3980
+ tracked_listeners.set(element, listeners);
3981
+ if (listeners[key] !== listener) {
3982
+ const options = { capture: key.endsWith('Capture') };
3983
+ if (_.isFunction(listeners[key]))
3984
+ element.removeEventListener(event, listeners[key], options);
3985
+ if (_.isFunction(listener))
3986
+ element.addEventListener(event, listener, options);
3987
+ }
3988
+ listeners[key] = listener;
3989
+ };
3990
+ const DOMUtils = new class {
3991
+ update(element, { className, style, ...props }) {
3992
+ if (className) {
3993
+ if (element.className !== className)
3994
+ element.className = className;
3995
+ }
3996
+ else if (!_.isNil(element.getAttribute('class'))) {
3997
+ element.removeAttribute('class');
3998
+ }
3999
+ if (style) {
4000
+ const oldValue = element.getAttribute('style');
4001
+ if (oldValue !== style)
4002
+ element.setAttribute('style', style);
4003
+ }
4004
+ else if (!_.isNil(element.getAttribute('style'))) {
4005
+ element.removeAttribute('style');
4006
+ }
4007
+ for (const [key, value] of _.entries(props)) {
4008
+ if (_.includes(globalEvents, key)) {
4009
+ _updateEventListener(element, key, value);
4010
+ }
4011
+ else if (key.endsWith('Capture') && _.includes(globalEvents, key.slice(0, -7))) {
4012
+ _updateEventListener(element, key, value);
4013
+ }
4014
+ else if (key.startsWith('data-')) {
4015
+ const oldValue = element.getAttribute(key);
4016
+ if (value === false || _.isNil(value)) {
4017
+ if (!_.isNil(oldValue))
4018
+ element.removeAttribute(key);
4019
+ }
4020
+ else {
4021
+ const newValue = value === true ? '' : `${value}`;
4022
+ if (oldValue !== newValue)
4023
+ element.setAttribute(key, newValue);
4024
+ }
4025
+ }
4026
+ else {
4027
+ const tagName = _.toLower(element.tagName);
4028
+ const { type: _type, attr } = htmlProps['*'][key]
4029
+ ?? htmlProps[tagName]?.[key]
4030
+ ?? svgProps['*'][key]
4031
+ ?? svgProps[tagName]?.[key]
4032
+ ?? {};
4033
+ const writeable = isWriteable(element, key);
4034
+ if (writeable && !_.isNil(value)) {
4035
+ if (element[key] !== value)
4036
+ element[key] = value;
4037
+ }
4038
+ else if (_type && attr && _propValue[_type]) {
4039
+ const oldValue = element.getAttribute(attr);
4040
+ if (value === false || _.isNil(value)) {
4041
+ if (!_.isNil(oldValue))
4042
+ element.removeAttribute(attr);
4043
+ }
4044
+ else {
4045
+ const newValue = value === true ? '' : `${value}`;
4046
+ if (oldValue !== newValue)
4047
+ element.setAttribute(attr, newValue);
4048
+ }
4049
+ }
4050
+ else if (writeable) {
4051
+ if (element[key] !== value)
4052
+ element[key] = value;
4053
+ }
4054
+ }
4055
+ }
4056
+ }
4057
+ replaceChildren(element, children, shouldRemove = () => true) {
4058
+ const document = element.ownerDocument;
4059
+ const diff = myersSync(_.map(element.childNodes, x => x.nodeType === document.TEXT_NODE ? x.textContent ?? '' : x), _.flatMap(children, x => x instanceof DOMNativeNode ? x.target : x), { compare: (a, b) => a === b });
4060
+ let i = 0;
4061
+ for (const { remove, insert, equivalent } of diff) {
4062
+ if (equivalent) {
4063
+ i += equivalent.length;
4064
+ }
4065
+ else if (remove) {
4066
+ for (const child of remove) {
4067
+ if (_.isString(child) || shouldRemove(child)) {
4068
+ element.removeChild(element.childNodes[i]);
4069
+ }
4070
+ else {
4071
+ i++;
4072
+ }
4073
+ }
4074
+ }
4075
+ if (insert) {
4076
+ for (const child of insert) {
4077
+ const node = _.isString(child) ? document.createTextNode(child) : child;
4078
+ element.insertBefore(node, element.childNodes[i++]);
4079
+ }
4080
+ }
4081
+ }
4082
+ }
4083
+ destroyElement(element) {
4084
+ const listeners = tracked_listeners.get(element);
4085
+ for (const [key, listener] of _.entries(listeners)) {
4086
+ const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();
4087
+ if (_.isFunction(listener)) {
4088
+ element.removeEventListener(event, listener, { capture: key.endsWith('Capture') });
4089
+ }
4090
+ }
4091
+ tracked_listeners.delete(element);
4092
+ }
4093
+ };
4094
+ class DOMNativeNode extends NativeElementType {
4095
+ static get Utils() { return DOMUtils; }
4096
+ static createElement;
4097
+ }
4098
+
4099
+ //
4100
+ // renderer.ts
4101
+ //
4102
+ // The MIT License
4103
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
4104
+ //
4105
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4106
+ // of this software and associated documentation files (the "Software"), to deal
4107
+ // in the Software without restriction, including without limitation the rights
4108
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4109
+ // copies of the Software, and to permit persons to whom the Software is
4110
+ // furnished to do so, subject to the following conditions:
4111
+ //
4112
+ // The above copyright notice and this permission notice shall be included in
4113
+ // all copies or substantial portions of the Software.
4114
+ //
4115
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4116
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4117
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4118
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4119
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4120
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4121
+ // THE SOFTWARE.
4122
+ //
4123
+ const SVG_NS = 'http://www.w3.org/2000/svg';
4124
+ const HTML_NS = 'http://www.w3.org/1999/xhtml';
4125
+ const MATHML_NS = 'http://www.w3.org/1998/Math/MathML';
4126
+ class _DOMRenderer extends _Renderer {
4127
+ _window;
4128
+ _namespace_map = new WeakMap();
4129
+ _tracked_head_children = [];
4130
+ _tracked_style = new StyleBuilder();
4131
+ /** @internal */
4132
+ _tracked_server_resource = new Map();
4133
+ _tracked_elements = new Map();
4134
+ constructor(window) {
4135
+ super();
4136
+ this._window = window;
4137
+ }
4138
+ get document() {
4139
+ return this.window.document;
4140
+ }
4141
+ get window() {
4142
+ return this._window;
4143
+ }
4144
+ /** @internal */
4145
+ _beforeUpdate() {
4146
+ if (this._server) {
4147
+ this._tracked_head_children = [];
4148
+ this._tracked_server_resource = new Map();
4149
+ }
4150
+ }
4151
+ /** @internal */
4152
+ _afterUpdate() {
4153
+ this._tracked_style.select([...this._tracked_elements.values().flatMap(({ className }) => className)]);
4154
+ const head = this.document.head ?? this.document.createElementNS(HTML_NS, 'head');
4155
+ const styleElem = this.document.querySelector('style[data-frosty-style]') ?? this.document.createElementNS(HTML_NS, 'style');
4156
+ styleElem.setAttribute('data-frosty-style', '');
4157
+ if (styleElem.textContent !== this._tracked_style.css)
4158
+ styleElem.textContent = this._tracked_style.css;
4159
+ if (this._server) {
4160
+ const ssrData = this._tracked_server_resource.size ? this.document.createElementNS(HTML_NS, 'script') : undefined;
4161
+ if (ssrData) {
4162
+ ssrData.setAttribute('data-frosty-ssr-data', '');
4163
+ ssrData.setAttribute('type', 'text/plain');
4164
+ ssrData.innerHTML = compress(JSON.stringify(Object.fromEntries(this._tracked_server_resource)));
4165
+ }
4166
+ DOMNativeNode.Utils.replaceChildren(head, _.compact([
4167
+ ...this._tracked_head_children,
4168
+ styleElem.textContent && styleElem,
4169
+ ssrData,
4170
+ ]), (x) => this._tracked_elements.has(x));
4171
+ }
4172
+ else if (styleElem.parentNode !== head && styleElem.textContent) {
4173
+ head.appendChild(styleElem);
4174
+ }
4175
+ if (!this.document.head) {
4176
+ this.document.documentElement.insertBefore(head, this.document.body);
4032
4177
  }
4033
4178
  }
4034
4179
  /** @internal */
@@ -4040,7 +4185,6 @@ class _DOMRenderer extends _Renderer {
4040
4185
  this._tracked_elements.set(elem, {
4041
4186
  props: [],
4042
4187
  className: [],
4043
- listener: {},
4044
4188
  });
4045
4189
  this._updateElement(node, elem, stack);
4046
4190
  return elem;
@@ -4064,7 +4208,6 @@ class _DOMRenderer extends _Renderer {
4064
4208
  this._tracked_elements.set(elem, {
4065
4209
  props: [],
4066
4210
  className: [],
4067
- listener: {},
4068
4211
  });
4069
4212
  this._updateElement(node, elem, stack);
4070
4213
  return elem;
@@ -4077,20 +4220,6 @@ class _DOMRenderer extends _Renderer {
4077
4220
  tracked.className = built;
4078
4221
  return [..._className, ...built].join(' ');
4079
4222
  }
4080
- __updateEventListener(element, key, listener) {
4081
- const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();
4082
- const tracked_listener = this._tracked_elements.get(element)?.listener;
4083
- if (!tracked_listener)
4084
- return;
4085
- if (tracked_listener[key] !== listener) {
4086
- const options = { capture: key.endsWith('Capture') };
4087
- if (_.isFunction(tracked_listener[key]))
4088
- element.removeEventListener(event, tracked_listener[key], options);
4089
- if (_.isFunction(listener))
4090
- element.addEventListener(event, listener, options);
4091
- }
4092
- tracked_listener[key] = listener;
4093
- }
4094
4223
  /** @internal */
4095
4224
  _updateElement(node, element, stack) {
4096
4225
  if (element instanceof DOMNativeNode) {
@@ -4116,83 +4245,20 @@ class _DOMRenderer extends _Renderer {
4116
4245
  }
4117
4246
  if (ref)
4118
4247
  mergeRefs(ref)(element);
4119
- const builtClassName = this.__createBuiltClassName(element, className, style);
4120
- if (_.isEmpty(builtClassName)) {
4121
- if (!_.isNil(element.getAttribute('class')))
4122
- element.removeAttribute('class');
4123
- }
4124
- else if (element.className !== builtClassName) {
4125
- element.className = builtClassName;
4126
- }
4127
- if (!_.isEmpty(innerHTML) && element.innerHTML !== innerHTML)
4128
- element.innerHTML = innerHTML;
4129
- if (inlineStyle) {
4130
- const { css } = processCss(inlineStyle);
4131
- const oldValue = element.getAttribute('style');
4132
- const newValue = css.split('\n').join('');
4133
- if (oldValue !== newValue)
4134
- element.setAttribute('style', newValue);
4135
- }
4136
- else if (!_.isNil(element.getAttribute('style'))) {
4137
- element.removeAttribute('style');
4138
- }
4139
4248
  const tracked = this._tracked_elements.get(element);
4140
4249
  if (!tracked)
4141
4250
  return;
4142
4251
  const removed = _.difference(tracked.props, _.keys(_props));
4143
- const props = {
4252
+ tracked.props = _.keys(_props);
4253
+ const builtClassName = this.__createBuiltClassName(element, className, style);
4254
+ if (!_.isEmpty(innerHTML) && element.innerHTML !== innerHTML)
4255
+ element.innerHTML = innerHTML;
4256
+ DOMNativeNode.Utils.update(element, {
4257
+ className: builtClassName,
4258
+ style: inlineStyle ? processCss(inlineStyle).css : undefined,
4144
4259
  ..._props,
4145
4260
  ..._.fromPairs(_.map(removed, x => [x, undefined])),
4146
- };
4147
- tracked.props = _.keys(_props);
4148
- for (const [key, value] of _.entries(props)) {
4149
- if (_.includes(globalEvents, key)) {
4150
- this.__updateEventListener(element, key, value);
4151
- }
4152
- else if (key.endsWith('Capture') && _.includes(globalEvents, key.slice(0, -7))) {
4153
- this.__updateEventListener(element, key, value);
4154
- }
4155
- else if (key.startsWith('data-')) {
4156
- const oldValue = element.getAttribute(key);
4157
- if (value === false || _.isNil(value)) {
4158
- if (!_.isNil(oldValue))
4159
- element.removeAttribute(key);
4160
- }
4161
- else {
4162
- const newValue = value === true ? '' : `${value}`;
4163
- if (oldValue !== newValue)
4164
- element.setAttribute(key, newValue);
4165
- }
4166
- }
4167
- else {
4168
- const { type: _type, attr } = htmlProps['*'][key]
4169
- ?? htmlProps[type]?.[key]
4170
- ?? svgProps['*'][key]
4171
- ?? svgProps[type]?.[key]
4172
- ?? {};
4173
- const writeable = isWriteable(element, key);
4174
- if (writeable && !_.isNil(value)) {
4175
- if (element[key] !== value)
4176
- element[key] = value;
4177
- }
4178
- else if (_type && attr && _propValue[_type]) {
4179
- const oldValue = element.getAttribute(key);
4180
- if (value === false || _.isNil(value)) {
4181
- if (!_.isNil(oldValue))
4182
- element.removeAttribute(key);
4183
- }
4184
- else {
4185
- const newValue = value === true ? '' : `${value}`;
4186
- if (oldValue !== newValue)
4187
- element.setAttribute(key, newValue);
4188
- }
4189
- }
4190
- else if (writeable) {
4191
- if (element[key] !== value)
4192
- element[key] = value;
4193
- }
4194
- }
4195
- }
4261
+ });
4196
4262
  }
4197
4263
  /** @internal */
4198
4264
  _replaceChildren(node, element, children, stack, force) {
@@ -4205,7 +4271,7 @@ class _DOMRenderer extends _Renderer {
4205
4271
  this._tracked_head_children.push(...children);
4206
4272
  }
4207
4273
  else if (_.isEmpty(innerHTML)) {
4208
- this.__replaceChildren(element, children, force);
4274
+ DOMNativeNode.Utils.replaceChildren(element, children, (x) => !!force || this._tracked_elements.has(x));
4209
4275
  }
4210
4276
  }
4211
4277
  }
@@ -4215,39 +4281,7 @@ class _DOMRenderer extends _Renderer {
4215
4281
  element.destroy();
4216
4282
  }
4217
4283
  else {
4218
- const tracked_listener = this._tracked_elements.get(element)?.listener;
4219
- for (const [key, listener] of _.entries(tracked_listener)) {
4220
- const event = key.endsWith('Capture') ? key.slice(2, -7).toLowerCase() : key.slice(2).toLowerCase();
4221
- if (_.isFunction(listener)) {
4222
- element.removeEventListener(event, listener, { capture: key.endsWith('Capture') });
4223
- }
4224
- }
4225
- }
4226
- this._tracked_elements.delete(element);
4227
- }
4228
- __replaceChildren(element, children, force) {
4229
- const diff = myersSync(_.map(element.childNodes, x => x.nodeType === this.document.TEXT_NODE ? x.textContent ?? '' : x), _.flatMap(children, x => x instanceof DOMNativeNode ? x.target : x), { compare: (a, b) => a === b });
4230
- let i = 0;
4231
- for (const { remove, insert, equivalent } of diff) {
4232
- if (equivalent) {
4233
- i += equivalent.length;
4234
- }
4235
- else if (remove) {
4236
- for (const child of remove) {
4237
- if (force || _.isString(child) || this._tracked_elements.has(child)) {
4238
- element.removeChild(element.childNodes[i]);
4239
- }
4240
- else {
4241
- i++;
4242
- }
4243
- }
4244
- }
4245
- if (insert) {
4246
- for (const child of insert) {
4247
- const node = _.isString(child) ? this.document.createTextNode(child) : child;
4248
- element.insertBefore(node, element.childNodes[i++]);
4249
- }
4250
- }
4284
+ DOMNativeNode.Utils.destroyElement(element);
4251
4285
  }
4252
4286
  }
4253
4287
  async renderToString(component) {
@@ -4265,4 +4299,4 @@ class _DOMRenderer extends _Renderer {
4265
4299
  }
4266
4300
 
4267
4301
  export { DOMNativeNode as D, _DOMRenderer as _ };
4268
- //# sourceMappingURL=common-D932m3CD.mjs.map
4302
+ //# sourceMappingURL=renderer-mmUwu_Ch.mjs.map