@uniformdev/context-vue 17.7.0 → 17.7.1-alpha.167

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/dist/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import * as vue_demi from 'vue-demi';
2
2
  import { ConcreteComponent, PropType, App } from 'vue-demi';
3
3
  import { PersonalizedVariant, TestVariant, EnrichmentData, Context, Quirks, ScoreVector } from '@uniformdev/context';
4
- import * as _uniformdev_context_dist_types_cb64a6b4 from '@uniformdev/context/dist/types-cb64a6b4';
4
+ import * as _uniformdev_context_dist_types_1c9fdbd2 from '@uniformdev/context/dist/types-1c9fdbd2';
5
5
 
6
- declare type PersonalizedVariationComponentProps = PersonalizedVariant & {
6
+ type PersonalizedVariationComponentProps = PersonalizedVariant & {
7
7
  personalizationResult: {
8
8
  variation: PersonalizedVariant;
9
9
  personalizationOccurred: boolean;
10
10
  };
11
11
  };
12
- declare type PersonalizedVariationComponent = (variation: PersonalizedVariationComponentProps) => ConcreteComponent<any>;
13
- declare type PersonalizeComponentProps = {
12
+ type PersonalizedVariationComponent = (variation: PersonalizedVariationComponentProps) => ConcreteComponent<any>;
13
+ type PersonalizeComponentProps = {
14
14
  /**
15
15
  * Name of the personalized placement. Should be unique to this placement location and set of variants.
16
16
  * This name is emitted to analytics after personalization executes.
@@ -69,7 +69,7 @@ declare const PersonalizeStandard: vue_demi.DefineComponent<{
69
69
  required: true;
70
70
  };
71
71
  variations: {
72
- type: PropType<_uniformdev_context_dist_types_cb64a6b4.a2[]>;
72
+ type: PropType<_uniformdev_context_dist_types_1c9fdbd2.a2[]>;
73
73
  required: true;
74
74
  };
75
75
  component: {
@@ -90,7 +90,7 @@ declare const PersonalizeStandard: vue_demi.DefineComponent<{
90
90
  required: true;
91
91
  };
92
92
  variations: {
93
- type: PropType<_uniformdev_context_dist_types_cb64a6b4.a2[]>;
93
+ type: PropType<_uniformdev_context_dist_types_1c9fdbd2.a2[]>;
94
94
  required: true;
95
95
  };
96
96
  component: {
@@ -211,8 +211,8 @@ declare const TrackSlot: vue_demi.DefineComponent<{
211
211
  };
212
212
  }>>, {}>;
213
213
 
214
- declare type VariantOutputType = 'edge' | 'standard';
215
- declare type UniformContextProps = {
214
+ type VariantOutputType = 'edge' | 'standard';
215
+ type UniformContextProps = {
216
216
  /** The configured Uniform Context instance to provide */
217
217
  context: Context;
218
218
  /** The output type to emit.
package/dist/index.esm.js CHANGED
@@ -1 +1,554 @@
1
- import{defineComponent as ue,h as de}from"vue-demi";import{parse as J}from"cookie-es";import{getCurrentInstance as K,inject as Q,provide as $}from"vue-demi";var d=typeof window=="undefined";var l="uniformContextInjectionKey",g=({context:e,outputType:t="standard",trackRouteOnRender:o=!0,vueAppInstance:r})=>{let i={context:e,outputType:t};r?r.provide(l,i):$(l,i),o&&I(e)};function I(e){d||e==null||e.update({url:new URL(window.location.href),cookies:J(document.cookie)})}var n=()=>{let e=Q(l);if(!e)throw Error("Could not inject Uniform's Context, make sure you're using <UniformContextProvider /> or the Uniform Nuxt module with a valid manifest.");return e};function G(){var t;return Boolean((t=K())==null?void 0:t.appContext.provides[l])}import{EdgeNodeTagName as T,ScriptType as C}from"@uniformdev/context";import{defineComponent as W,h as c}from"vue-demi";var X=W({name:"PersonalizeStandard",inheritAttrs:!1,props:{name:{type:String,required:!0},variations:{type:Array,required:!0},component:{type:[Function,Object],required:!0},count:{type:Number,default:1}},setup(e){var o;let t={name:e.name,count:(o=e.count)!=null?o:1};return()=>[c(T,{"data-type":C.ListStart,innerHTML:JSON.stringify(t)}),e.variations.map(r=>[c(T,{"data-type":C.ListItemSettings,innerHTML:JSON.stringify({id:r.id,pz:r.pz||null}),key:`LIS-${r.id}`}),c(T,{"data-type":C.ListItem,key:`LI-${r.id}`},c(e.component,{personalizationResult:{variation:r,personalizationOccurred:!1},...r}))]),c(T,{"data-type":C.ListEnd})]}}),b=X;import{defineComponent as ae,h as w,ref as se,toRaw as k,watch as pe}from"vue-demi";import{dequal as Y}from"dequal/lite";import{ref as Z,watchEffect as ee}from"vue-demi";var S=()=>{let{context:e}=n(),t=Z(e.scores);return ee(()=>{let o=i=>t.value=i,r=e.scores;return Y(t.value,r)||(t.value=r),e.events.on("scoresUpdated",o),()=>{e.events.off("scoresUpdated",o)}}),t};import{defineComponent as re,h as ne}from"vue-demi";import{inject as te,provide as oe}from"vue-demi";var V=Symbol("uniformIsPersonalized"),U=e=>{oe(V,e)},f=()=>te(V,!1);var ie=re({name:"PersonalizeProvider",inheritAttrs:!1,props:{personalized:Boolean},setup(e,t){return U(e.personalized),()=>ne(t.slots.default,{...e})}}),q=ie;var me=ae({name:"PersonalizeStandard",inheritAttrs:!1,props:{name:{type:String,required:!0},variations:{type:Array,required:!0},component:{type:[Function,Object],required:!0},count:{type:Number,default:1}},setup(e){let{context:t}=n(),o=S(),r=()=>{var a;return t.personalize({name:k(e.name),variations:k(e.variations),take:(a=k(e.count))!=null?a:1})},i=se(r());return pe([o,()=>e.name,()=>e.variations,()=>e.count],()=>{i.value=r()}),()=>w(q,{personalized:!0},()=>{var a;return(a=i.value)==null?void 0:a.variations.map(s=>{var u;return w(e.component,{key:s.id,personalizationResult:{variation:s,personalizationOccurred:(u=i.value)==null?void 0:u.personalized},...s})})})}}),L=me;var le=ue({name:"Personalize",inheritAttrs:!1,props:{name:{type:String,required:!0},variations:{type:Array,required:!0},component:{type:[Function,Object],required:!0},count:{type:Number,default:1}},setup(e){let{outputType:t}=n();return()=>de(!d||t==="standard"?L:b,{...e})}}),ce=le;import{defineComponent as ve,h as H}from"vue-demi";import{EdgeNodeTagName as v,ScriptType as h}from"@uniformdev/context";import{defineComponent as fe,h as y}from"vue-demi";var ye=fe({name:"TestEdge",inheritAttrs:!1,props:{name:{type:String,required:!0},variations:{type:Array,required:!0},component:{type:[Object,Function],required:!0}},setup(e){let t={name:e.name};return()=>[y(v,{"data-type":h.TestStart,innerHTML:JSON.stringify(t)}),e.variations.map(o=>[y(v,{"data-type":h.ListItemSettings,key:`LIS-${o.id}`,innerHTML:JSON.stringify({id:o.id})}),y(v,{"data-type":h.ListItem,key:`LI-${o.id}`},y(e.component,{...o}))]),y(v,{"data-type":h.TestEnd})]}}),N=ye;import{defineComponent as Pe,h as Te,toRaw as R}from"vue-demi";var Ce=Pe({name:"TestStandard",inheritAttrs:!1,props:{name:{type:String,required:!0},variations:{type:Array,required:!0},component:{type:[Object,Function],required:!0}},setup(e){let{context:t}=n(),{result:o}=t.test({name:R(e.name),variations:R(e.variations)});return o?()=>Te(e.component,{...o}):()=>null}}),j=Ce;var he=ve({name:"Test",inheritAttrs:!1,props:{name:{type:String,required:!0},variations:{type:Array,required:!0},component:{type:[Object,Function],required:!0}},setup(e){let{outputType:t}=n();return()=>!d||t==="standard"?H(j,{...e}):H(N,{...e})}}),xe=he;import{defineComponent as ze,h as ge,ref as x,toRaw as be,watchEffect as D}from"vue-demi";var Se=ze({name:"Track",inheritAttrs:!1,props:{behavior:{type:[Object,Array]},tagName:{type:String,default:"div"},disableVisibilityTrigger:{type:Boolean,default:typeof window=="undefined"||!("IntersectionObserver"in window)},threshold:{type:[Number,Array],default:.5}},setup(e,t){let o=typeof document=="undefined"?"__uniform_ssr_url":document.location.href,{context:r}=n(),i=f(),a=x(""),s=x(!1),u=x(),p=x();return D(()=>{a.value!==o&&(a.value=o,s.value=!1)}),D(()=>{var O;let z=!e.behavior||Array.isArray(e.behavior)&&!e.behavior.length;if(i||z||!u.value)return;let M=Array.isArray(e.behavior)?e.behavior:[e.behavior],A=()=>{var m;s.value||(r==null||r.update({enrichments:be(M)}),s.value=!1,(m=p.value)==null||m.call(p))};if(e.disableVisibilityTrigger)A();else{(O=p.value)==null||O.call(p);let m=new IntersectionObserver(([P])=>{P.isIntersecting&&A()},{threshold:e.threshold});m.observe(u.value),p.value=()=>{var P;return(P=m.disconnect)==null?void 0:P.call(m)}}return()=>{var m;(m=p.value)==null||m.call(p)}}),()=>ge(e.tagName,{ref:u,...t.attrs},t.slots.default())}}),Ue=Se;import{defineComponent as ke,h as Ee,ref as _,toRaw as Ae,watchEffect as B}from"vue-demi";var Oe=ke({name:"TrackSlot",inheritAttrs:!1,props:{behavior:{type:[Object,Array]}},setup(e,t){let o=typeof document=="undefined"?"__uniform_ssr_url":document.location.href,{context:r}=n(),i=f(),a=_(),s=_(!1);return B(()=>{a.value!==o&&(a.value=o,s.value=!1)}),B(()=>{let u=!e.behavior||Array.isArray(e.behavior)&&!e.behavior.length;if(i||u)return;(()=>{if(s.value)return;let E=Array.isArray(e.behavior)?e.behavior:[e.behavior];r==null||r.update({enrichments:Ae(E)}),s.value=!0})()}),()=>Ee(t.slots.default,{...t.attrs})}}),Ie=Oe;import{SERVER_STATE_ID as Ve}from"@uniformdev/context";import{defineComponent as qe,h as F}from"vue-demi";var we=qe({name:"UniformContextProvider",inheritAttrs:!1,props:{context:{type:Object,required:!0},outputType:{type:String,default:"standard"},trackRouteOnRender:{type:Boolean,default:!0}},setup(e,t){return g(e),()=>[F(t.slots.default),Ne(e.context)]}}),Le=we;function Ne(e){let t=e.getServerToClientTransitionState();return()=>F("script",{id:Ve,type:"application/json",innerHTML:JSON.stringify(t)})}import{ref as Re,watch as je}from"vue-demi";var He=()=>{let{context:e}=n(),t=Re(e.quirks),o=r=>{t.value=r};return je(e,()=>(e.events.on("quirksUpdated",o),()=>{e.events.off("quirksUpdated",o)})),t};export{ce as Personalize,b as PersonalizeEdge,xe as Test,Ue as Track,Ie as TrackSlot,Le as UniformContextProvider,G as isUsingUniformContext,I as onRouteChange,U as provideIsPersonalized,g as provideUniformContext,l as uniformContextInjectionKey,f as useIsPersonalized,He as useQuirks,S as useScores,n as useUniformContext};
1
+ // src/components/personalize/Personalize.ts
2
+ import { defineComponent as defineComponent4, h as h4 } from "vue-demi";
3
+
4
+ // src/providers/useUniformContext.ts
5
+ import { parse as parseCookie } from "cookie-es";
6
+ import { getCurrentInstance, inject, provide } from "vue-demi";
7
+
8
+ // src/utils/constants.ts
9
+ var isServer = typeof window === "undefined";
10
+
11
+ // src/providers/useUniformContext.ts
12
+ var uniformContextInjectionKey = "uniformContextInjectionKey";
13
+ var provideUniformContext = ({
14
+ context,
15
+ outputType = "standard",
16
+ trackRouteOnRender = true,
17
+ vueAppInstance
18
+ }) => {
19
+ const payload = {
20
+ context,
21
+ outputType
22
+ };
23
+ if (vueAppInstance) {
24
+ vueAppInstance.provide(uniformContextInjectionKey, payload);
25
+ } else {
26
+ provide(uniformContextInjectionKey, payload);
27
+ }
28
+ if (trackRouteOnRender) {
29
+ onRouteChange(context);
30
+ }
31
+ };
32
+ function onRouteChange(context) {
33
+ if (isServer) {
34
+ return;
35
+ }
36
+ context == null ? void 0 : context.update({
37
+ url: new URL(window.location.href),
38
+ cookies: parseCookie(document.cookie)
39
+ });
40
+ }
41
+ var useUniformContext = () => {
42
+ const contextData = inject(uniformContextInjectionKey);
43
+ if (!contextData) {
44
+ throw Error(
45
+ `Could not inject Uniform's Context, make sure you're using <UniformContextProvider /> or the Uniform Nuxt module with a valid manifest.`
46
+ );
47
+ }
48
+ return contextData;
49
+ };
50
+ function isUsingUniformContext() {
51
+ var _a;
52
+ const isUniformContextProvided = Boolean(
53
+ (_a = getCurrentInstance()) == null ? void 0 : _a.appContext.provides[uniformContextInjectionKey]
54
+ );
55
+ return isUniformContextProvided;
56
+ }
57
+
58
+ // src/components/personalize/PersonalizeEdge.ts
59
+ import { EdgeNodeTagName, ScriptType } from "@uniformdev/context";
60
+ import { defineComponent, h } from "vue-demi";
61
+ var PersonalizeStandard = defineComponent({
62
+ name: "PersonalizeStandard",
63
+ inheritAttrs: false,
64
+ props: {
65
+ name: {
66
+ type: String,
67
+ required: true
68
+ },
69
+ variations: {
70
+ type: Array,
71
+ required: true
72
+ },
73
+ component: {
74
+ type: [Function, Object],
75
+ required: true
76
+ },
77
+ count: {
78
+ type: Number,
79
+ default: 1
80
+ }
81
+ },
82
+ setup(props) {
83
+ var _a;
84
+ const options = {
85
+ name: props.name,
86
+ count: (_a = props.count) != null ? _a : 1
87
+ };
88
+ return () => [
89
+ h(EdgeNodeTagName, { "data-type": ScriptType.ListStart, innerHTML: JSON.stringify(options) }),
90
+ props.variations.map((variant) => {
91
+ return [
92
+ h(EdgeNodeTagName, {
93
+ "data-type": ScriptType.ListItemSettings,
94
+ innerHTML: JSON.stringify({ id: variant.id, pz: variant.pz || null }),
95
+ key: `LIS-${variant.id}`
96
+ }),
97
+ h(
98
+ EdgeNodeTagName,
99
+ { "data-type": ScriptType.ListItem, key: `LI-${variant.id}` },
100
+ h(props.component, {
101
+ personalizationResult: { variation: variant, personalizationOccurred: false },
102
+ ...variant
103
+ })
104
+ )
105
+ ];
106
+ }),
107
+ h(EdgeNodeTagName, { "data-type": ScriptType.ListEnd })
108
+ ];
109
+ }
110
+ });
111
+ var PersonalizeEdge_default = PersonalizeStandard;
112
+
113
+ // src/components/personalize/PersonalizeStandard.ts
114
+ import { defineComponent as defineComponent3, h as h3, ref as ref2, toRaw, watch } from "vue-demi";
115
+
116
+ // src/providers/useScores.ts
117
+ import { dequal } from "dequal/lite";
118
+ import { ref, watchEffect } from "vue-demi";
119
+ var useScores = () => {
120
+ const { context } = useUniformContext();
121
+ const scores = ref(context.scores);
122
+ watchEffect(() => {
123
+ const scoringChangeListener = (updatedScores) => scores.value = updatedScores;
124
+ const currentScores = context.scores;
125
+ if (!dequal(scores.value, currentScores)) {
126
+ scores.value = currentScores;
127
+ }
128
+ context.events.on("scoresUpdated", scoringChangeListener);
129
+ return () => {
130
+ context.events.off("scoresUpdated", scoringChangeListener);
131
+ };
132
+ });
133
+ return scores;
134
+ };
135
+
136
+ // src/components/personalize/PersonalizeProvider.ts
137
+ import { defineComponent as defineComponent2, h as h2 } from "vue-demi";
138
+
139
+ // src/providers/useIsPersonalized.ts
140
+ import { inject as inject2, provide as provide2 } from "vue-demi";
141
+ var isPersonalizedSymbol = Symbol("uniformIsPersonalized");
142
+ var provideIsPersonalized = (isPersonalized) => {
143
+ provide2(isPersonalizedSymbol, isPersonalized);
144
+ };
145
+ var useIsPersonalized = () => {
146
+ return inject2(isPersonalizedSymbol, false);
147
+ };
148
+
149
+ // src/components/personalize/PersonalizeProvider.ts
150
+ var PersonalizeProvider = defineComponent2({
151
+ name: "PersonalizeProvider",
152
+ inheritAttrs: false,
153
+ props: {
154
+ personalized: Boolean
155
+ },
156
+ setup(props, context) {
157
+ provideIsPersonalized(props.personalized);
158
+ return () => h2(context.slots.default, {
159
+ ...props
160
+ });
161
+ }
162
+ });
163
+ var PersonalizeProvider_default = PersonalizeProvider;
164
+
165
+ // src/components/personalize/PersonalizeStandard.ts
166
+ var PersonalizeStandard2 = defineComponent3({
167
+ name: "PersonalizeStandard",
168
+ inheritAttrs: false,
169
+ props: {
170
+ name: {
171
+ type: String,
172
+ required: true
173
+ },
174
+ variations: {
175
+ type: Array,
176
+ required: true
177
+ },
178
+ component: {
179
+ type: [Function, Object],
180
+ required: true
181
+ },
182
+ count: {
183
+ type: Number,
184
+ default: 1
185
+ }
186
+ },
187
+ setup(props) {
188
+ const { context: uniformContext } = useUniformContext();
189
+ const scores = useScores();
190
+ const personalize = () => {
191
+ var _a;
192
+ return uniformContext.personalize({
193
+ name: toRaw(props.name),
194
+ variations: toRaw(props.variations),
195
+ take: (_a = toRaw(props.count)) != null ? _a : 1
196
+ });
197
+ };
198
+ const personalizedResult = ref2(personalize());
199
+ watch([scores, () => props.name, () => props.variations, () => props.count], () => {
200
+ personalizedResult.value = personalize();
201
+ });
202
+ return () => h3(
203
+ PersonalizeProvider_default,
204
+ { personalized: true },
205
+ () => {
206
+ var _a;
207
+ return (_a = personalizedResult.value) == null ? void 0 : _a.variations.map((variation) => {
208
+ var _a2;
209
+ return h3(props.component, {
210
+ key: variation.id,
211
+ personalizationResult: {
212
+ variation,
213
+ personalizationOccurred: (_a2 = personalizedResult.value) == null ? void 0 : _a2.personalized
214
+ },
215
+ ...variation
216
+ });
217
+ });
218
+ }
219
+ );
220
+ }
221
+ });
222
+ var PersonalizeStandard_default = PersonalizeStandard2;
223
+
224
+ // src/components/personalize/Personalize.ts
225
+ var Personalize = defineComponent4({
226
+ name: "Personalize",
227
+ inheritAttrs: false,
228
+ props: {
229
+ name: {
230
+ type: String,
231
+ required: true
232
+ },
233
+ variations: {
234
+ type: Array,
235
+ required: true
236
+ },
237
+ component: {
238
+ type: [Function, Object],
239
+ required: true
240
+ },
241
+ count: {
242
+ type: Number,
243
+ default: 1
244
+ }
245
+ },
246
+ setup(props) {
247
+ const { outputType } = useUniformContext();
248
+ return () => h4(!isServer || outputType === "standard" ? PersonalizeStandard_default : PersonalizeEdge_default, { ...props });
249
+ }
250
+ });
251
+ var Personalize_default = Personalize;
252
+
253
+ // src/components/Test/Test.ts
254
+ import { defineComponent as defineComponent7, h as h7 } from "vue-demi";
255
+
256
+ // src/components/Test/TestEdge.ts
257
+ import { EdgeNodeTagName as EdgeNodeTagName2, ScriptType as ScriptType2 } from "@uniformdev/context";
258
+ import { defineComponent as defineComponent5, h as h5 } from "vue-demi";
259
+ var TestEdge = defineComponent5({
260
+ name: "TestEdge",
261
+ inheritAttrs: false,
262
+ props: {
263
+ name: {
264
+ type: String,
265
+ required: true
266
+ },
267
+ variations: {
268
+ type: Array,
269
+ required: true
270
+ },
271
+ component: {
272
+ type: [Object, Function],
273
+ required: true
274
+ }
275
+ },
276
+ setup(props) {
277
+ const options = {
278
+ name: props.name
279
+ };
280
+ return () => [
281
+ h5(EdgeNodeTagName2, { "data-type": ScriptType2.TestStart, innerHTML: JSON.stringify(options) }),
282
+ props.variations.map((variation) => {
283
+ return [
284
+ h5(EdgeNodeTagName2, {
285
+ "data-type": ScriptType2.ListItemSettings,
286
+ key: `LIS-${variation.id}`,
287
+ innerHTML: JSON.stringify({ id: variation.id })
288
+ }),
289
+ h5(
290
+ EdgeNodeTagName2,
291
+ { "data-type": ScriptType2.ListItem, key: `LI-${variation.id}` },
292
+ h5(props.component, { ...variation })
293
+ )
294
+ ];
295
+ }),
296
+ h5(EdgeNodeTagName2, { "data-type": ScriptType2.TestEnd })
297
+ ];
298
+ }
299
+ });
300
+ var TestEdge_default = TestEdge;
301
+
302
+ // src/components/Test/TestStandard.ts
303
+ import { defineComponent as defineComponent6, h as h6, toRaw as toRaw2 } from "vue-demi";
304
+ var TestStandard = defineComponent6({
305
+ name: "TestStandard",
306
+ inheritAttrs: false,
307
+ props: {
308
+ name: {
309
+ type: String,
310
+ required: true
311
+ },
312
+ variations: {
313
+ type: Array,
314
+ required: true
315
+ },
316
+ component: {
317
+ type: [Object, Function],
318
+ required: true
319
+ }
320
+ },
321
+ setup(props) {
322
+ const { context: uniformContext } = useUniformContext();
323
+ const { result } = uniformContext.test({
324
+ name: toRaw2(props.name),
325
+ variations: toRaw2(props.variations)
326
+ });
327
+ if (!result) {
328
+ return () => null;
329
+ }
330
+ return () => h6(props.component, { ...result });
331
+ }
332
+ });
333
+ var TestStandard_default = TestStandard;
334
+
335
+ // src/components/Test/Test.ts
336
+ var Test = defineComponent7({
337
+ name: "Test",
338
+ inheritAttrs: false,
339
+ props: {
340
+ name: {
341
+ type: String,
342
+ required: true
343
+ },
344
+ variations: {
345
+ type: Array,
346
+ required: true
347
+ },
348
+ component: {
349
+ type: [Object, Function],
350
+ required: true
351
+ }
352
+ },
353
+ setup(props) {
354
+ const { outputType } = useUniformContext();
355
+ return () => !isServer || outputType === "standard" ? h7(TestStandard_default, { ...props }) : h7(TestEdge_default, { ...props });
356
+ }
357
+ });
358
+ var Test_default = Test;
359
+
360
+ // src/components/track/Track.ts
361
+ import { defineComponent as defineComponent8, h as h8, ref as ref3, toRaw as toRaw3, watchEffect as watchEffect2 } from "vue-demi";
362
+ var Track = defineComponent8({
363
+ name: "Track",
364
+ inheritAttrs: false,
365
+ props: {
366
+ behavior: {
367
+ type: [Object, Array]
368
+ },
369
+ tagName: {
370
+ type: String,
371
+ default: "div"
372
+ },
373
+ disableVisibilityTrigger: {
374
+ type: Boolean,
375
+ default: typeof window === "undefined" || !("IntersectionObserver" in window)
376
+ },
377
+ threshold: {
378
+ type: [Number, Array],
379
+ default: 0.5
380
+ }
381
+ },
382
+ setup(props, context) {
383
+ const currentUrl = typeof document === "undefined" ? "__uniform_ssr_url" : document.location.href;
384
+ const { context: uniformContext } = useUniformContext();
385
+ const insidePersonalizeComponent = useIsPersonalized();
386
+ const lastUrl = ref3("");
387
+ const hasTracked = ref3(false);
388
+ const wrapperEl = ref3();
389
+ const disconnect = ref3();
390
+ watchEffect2(() => {
391
+ const urlHasChanged = lastUrl.value !== currentUrl;
392
+ if (urlHasChanged) {
393
+ lastUrl.value = currentUrl;
394
+ hasTracked.value = false;
395
+ }
396
+ });
397
+ watchEffect2(() => {
398
+ var _a;
399
+ const hasNoBehaviorValue = !props.behavior || Array.isArray(props.behavior) && !props.behavior.length;
400
+ const cannotTrack = insidePersonalizeComponent || hasNoBehaviorValue;
401
+ if (cannotTrack || !wrapperEl.value) {
402
+ return;
403
+ }
404
+ const enrichments = Array.isArray(props.behavior) ? props.behavior : [props.behavior];
405
+ const pushBehaviorEnrichment = () => {
406
+ var _a2;
407
+ if (hasTracked.value) {
408
+ return;
409
+ }
410
+ uniformContext == null ? void 0 : uniformContext.update({
411
+ enrichments: toRaw3(enrichments)
412
+ });
413
+ hasTracked.value = false;
414
+ (_a2 = disconnect.value) == null ? void 0 : _a2.call(disconnect);
415
+ };
416
+ if (props.disableVisibilityTrigger) {
417
+ pushBehaviorEnrichment();
418
+ } else {
419
+ (_a = disconnect.value) == null ? void 0 : _a.call(disconnect);
420
+ const instance = new IntersectionObserver(
421
+ ([entry]) => {
422
+ if (entry.isIntersecting) {
423
+ pushBehaviorEnrichment();
424
+ }
425
+ },
426
+ {
427
+ threshold: props.threshold
428
+ }
429
+ );
430
+ instance.observe(wrapperEl.value);
431
+ disconnect.value = () => {
432
+ var _a2;
433
+ return (_a2 = instance.disconnect) == null ? void 0 : _a2.call(instance);
434
+ };
435
+ }
436
+ return () => {
437
+ var _a2;
438
+ (_a2 = disconnect.value) == null ? void 0 : _a2.call(disconnect);
439
+ };
440
+ });
441
+ return () => h8(props.tagName, { ref: wrapperEl, ...context.attrs }, context.slots.default());
442
+ }
443
+ });
444
+ var Track_default = Track;
445
+
446
+ // src/components/track/TrackSlot.ts
447
+ import { defineComponent as defineComponent9, h as h9, ref as ref4, toRaw as toRaw4, watchEffect as watchEffect3 } from "vue-demi";
448
+ var TrackSlot = defineComponent9({
449
+ name: "TrackSlot",
450
+ inheritAttrs: false,
451
+ props: {
452
+ behavior: {
453
+ type: [Object, Array]
454
+ }
455
+ },
456
+ setup(props, context) {
457
+ const currentUrl = typeof document === "undefined" ? "__uniform_ssr_url" : document.location.href;
458
+ const { context: uniformContext } = useUniformContext();
459
+ const insidePersonalizeComponent = useIsPersonalized();
460
+ const lastUrl = ref4();
461
+ const hasTracked = ref4(false);
462
+ watchEffect3(() => {
463
+ const urlHasChanged = lastUrl.value !== currentUrl;
464
+ if (urlHasChanged) {
465
+ lastUrl.value = currentUrl;
466
+ hasTracked.value = false;
467
+ }
468
+ });
469
+ watchEffect3(() => {
470
+ const hasNoBehaviorValue = !props.behavior || Array.isArray(props.behavior) && !props.behavior.length;
471
+ const cannotTrack = insidePersonalizeComponent || hasNoBehaviorValue;
472
+ if (cannotTrack)
473
+ return;
474
+ const pushBehaviorEnrichment = () => {
475
+ if (hasTracked.value) {
476
+ return;
477
+ }
478
+ const enrichments = Array.isArray(props.behavior) ? props.behavior : [props.behavior];
479
+ uniformContext == null ? void 0 : uniformContext.update({
480
+ enrichments: toRaw4(enrichments)
481
+ });
482
+ hasTracked.value = true;
483
+ };
484
+ pushBehaviorEnrichment();
485
+ });
486
+ return () => h9(context.slots.default, { ...context.attrs });
487
+ }
488
+ });
489
+ var TrackSlot_default = TrackSlot;
490
+
491
+ // src/components/UniformContextProvider.ts
492
+ import { SERVER_STATE_ID } from "@uniformdev/context";
493
+ import { defineComponent as defineComponent10, h as h10 } from "vue-demi";
494
+ var UniformContextProvider = defineComponent10({
495
+ name: "UniformContextProvider",
496
+ inheritAttrs: false,
497
+ props: {
498
+ context: {
499
+ type: Object,
500
+ required: true
501
+ },
502
+ outputType: {
503
+ type: String,
504
+ default: "standard"
505
+ },
506
+ trackRouteOnRender: {
507
+ type: Boolean,
508
+ default: true
509
+ }
510
+ },
511
+ setup(props, context) {
512
+ provideUniformContext(props);
513
+ return () => [h10(context.slots.default), TransferState(props.context)];
514
+ }
515
+ });
516
+ var UniformContextProvider_default = UniformContextProvider;
517
+ function TransferState(context) {
518
+ const state = context.getServerToClientTransitionState();
519
+ return () => h10("script", { id: SERVER_STATE_ID, type: "application/json", innerHTML: JSON.stringify(state) });
520
+ }
521
+
522
+ // src/providers/useQuirks.ts
523
+ import { ref as ref5, watch as watch2 } from "vue-demi";
524
+ var useQuirks = () => {
525
+ const { context } = useUniformContext();
526
+ const quirks = ref5(context.quirks);
527
+ const quirkChangeListener = (updateQuirks) => {
528
+ quirks.value = updateQuirks;
529
+ };
530
+ watch2(context, () => {
531
+ context.events.on("quirksUpdated", quirkChangeListener);
532
+ return () => {
533
+ context.events.off("quirksUpdated", quirkChangeListener);
534
+ };
535
+ });
536
+ return quirks;
537
+ };
538
+ export {
539
+ Personalize_default as Personalize,
540
+ PersonalizeEdge_default as PersonalizeEdge,
541
+ Test_default as Test,
542
+ Track_default as Track,
543
+ TrackSlot_default as TrackSlot,
544
+ UniformContextProvider_default as UniformContextProvider,
545
+ isUsingUniformContext,
546
+ onRouteChange,
547
+ provideIsPersonalized,
548
+ provideUniformContext,
549
+ uniformContextInjectionKey,
550
+ useIsPersonalized,
551
+ useQuirks,
552
+ useScores,
553
+ useUniformContext
554
+ };