feature-toggle-api 4.1.0 → 5.0.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.
Files changed (53) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +14 -16
  3. package/dist/feature-toggle.js +227 -385
  4. package/dist/feature-toggle.js.map +1 -0
  5. package/dist/featureToggle.d.ts +3 -0
  6. package/dist/html-plugin.js +42 -0
  7. package/dist/html-plugin.js.map +1 -0
  8. package/dist/index.d.ts +5 -0
  9. package/dist/plugins/htmlplugin/plugin-html.d.ts +15 -0
  10. package/dist/plugins/urlplugin/plugin-url.d.ts +14 -0
  11. package/dist/{feature-toggle.d.ts → types.d.ts} +17 -54
  12. package/dist/url-plugin.js +40 -0
  13. package/dist/url-plugin.js.map +1 -0
  14. package/dist/vite.config.d.ts +2 -0
  15. package/package.json +26 -11
  16. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
  17. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
  18. package/dist/feature-toggle.min.cjs +0 -2
  19. package/dist/feature-toggle.min.cjs.map +0 -1
  20. package/dist/feature-toggle.min.js +0 -2
  21. package/dist/feature-toggle.min.js.map +0 -1
  22. package/dist/feature-toggle.umd.min.js +0 -2
  23. package/dist/feature-toggle.umd.min.js.map +0 -1
  24. package/dist/html-plugin.umd.min.js +0 -2
  25. package/dist/html-plugin.umd.min.js.map +0 -1
  26. package/dist/url-plugin.umd.min.js +0 -2
  27. package/dist/url-plugin.umd.min.js.map +0 -1
  28. package/docs/_config.yml +0 -1
  29. package/docs/example-intro.html +0 -75
  30. package/docs/example-setup.html +0 -55
  31. package/docs/example-visibility-basic.html +0 -144
  32. package/docs/readme.md +0 -628
  33. package/docs/vue-feature-toggle.min.js +0 -902
  34. package/examples/01_basic_esmodule.js +0 -10
  35. package/examples/02_basic_cjsmodule.cjs +0 -6
  36. package/examples/03_basic_scripttag.html +0 -24
  37. package/examples/04_example-htmlplugin.html +0 -35
  38. package/examples/05_example-urlplugin.html +0 -25
  39. package/examples/06_withListener.html +0 -21
  40. package/gulpfile.js +0 -65
  41. package/plugin-html.js +0 -1
  42. package/plugin-url.js +0 -1
  43. package/rollup.config.js +0 -107
  44. package/src/featureToggle.ts +0 -466
  45. package/src/index.ts +0 -10
  46. package/src/plugins/htmlplugin/plugin-html.ts +0 -83
  47. package/src/plugins/htmlplugin/readme.md +0 -221
  48. package/src/plugins/urlplugin/plugin-url.ts +0 -90
  49. package/src/plugins/urlplugin/readme.md +0 -92
  50. package/tests/featuretoggle.test.ts +0 -450
  51. package/tests/polyfills.ts +0 -20
  52. package/tsconfig.cjs.json +0 -12
  53. package/tsconfig.json +0 -12
@@ -1,466 +0,0 @@
1
- interface OnConfiguration {
2
- ignorePreviousRules: boolean
3
- }
4
- type Plugin = (api) => Partial<FeatureToggleApi>;
5
-
6
- type EventType = 'visibilityrule' | 'init' | 'registerEvent' | string;
7
- interface OnEvent {
8
- name: string,
9
- variant: string,
10
- data: any,
11
- result?: boolean
12
- }
13
-
14
- type FirstCharOfFeatureFlagKey = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' |
15
- 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
16
-
17
- type FeatureFlagKey = `${FirstCharOfFeatureFlagKey}${string}`;
18
- type FeatureFlag = boolean | ((rule:Rule) => boolean);
19
- interface FeatureToggleConfig {
20
- [key: FeatureFlagKey]: FeatureFlag,
21
- $plugins?: Plugin[]
22
- /**
23
- * @deprecated Use key`$plugins` instead.
24
- */
25
- _plugins?: Plugin[]
26
-
27
- /**
28
- * This rule will always run before the main rule.
29
- * If it returns false, the main rules will be skipped and false is returned
30
- */
31
- $required?: FeatureFlag
32
-
33
- /**
34
- * This rule will always run after the main rule.
35
- * If the main rule returns false, the result of the default rule will be taken.s
36
- */
37
- $default?: FeatureFlag
38
- }
39
-
40
- interface Rule {
41
- name: string,
42
- variant: string,
43
- data: any,
44
- _internalCall?: true,
45
- description?: string
46
- }
47
-
48
- interface FeatureToggleApiBase {
49
- name: string,
50
- setData(name: string, dataParam?: any): void;
51
- setData(name: string, variant: string, dataParam?: any): void,
52
- setData(nameParam: string, variantOrDataParam: string | { [key: string]: any },
53
- dataParam?: any): void;
54
-
55
- on(eventType: EventType, fn: (event: OnEvent) => void, config?: OnConfiguration): void;
56
- trigger(eventtype: EventType, param?: any);
57
- showLogs(showLogs?: boolean): void
58
-
59
- /**
60
- * @deprecated Use `featureToggle.isActive` instead.
61
- */
62
- isVisible(name: string, variant?: string, data?: any): boolean
63
-
64
- isActive(name: string, variant?: string, data?: any): boolean
65
-
66
- /**
67
- * @deprecated Use `featureToggle.setFlag` instead.
68
- */
69
- visibility(name: string, result: boolean | ((rule: Rule) => boolean)): void,
70
- /**
71
- * @deprecated Use `featureToggle.setFlag` instead.
72
- */
73
- visibility(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void
74
- /**
75
- * @deprecated Use `featureToggle.setFlag` instead.
76
- */
77
- visibility(name: string, variant: string | null, data: any, result: boolean | ((rule: Rule) => boolean)): void,
78
- /**
79
- * @deprecated Use `featureToggle.setFlag` instead.
80
- */
81
- visibility(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | (() => boolean)): void
82
-
83
- setFlag(name: string, result: boolean | ((rule: Rule) => boolean)): void,
84
- setFlag(name: string, variant: string | null, result: boolean | ((rule: Rule) => boolean)): void,
85
- setFlag(name: string, variant: string | null, data: any, result: boolean | ((rule: Rule) => boolean)): void,
86
- setFlag(name: string, resultOrVariant: string | null | boolean | ((rule: Rule) => boolean), resultOrData?: any, result?: boolean | (() => boolean)): void
87
-
88
- /**
89
- * @deprecated Use `featureToggle.setRequiredFlag` instead.
90
- */
91
- requiredVisibility(fn: boolean | ((result: Rule) => boolean)): void
92
-
93
- /**
94
- * @deprecated Use `featureToggle.setDefaultFlag` instead.
95
- */
96
- defaultVisibility(fn: boolean | ((result: Rule) => boolean)): void
97
-
98
- /**
99
- * This rule will run first and only if it is true, the feature.setFlag() - rules apply.
100
- * In other words: if the required-rule returns false, all feature.setFlag-rules return false - regardless of its normal result.
101
- * @param fn
102
- */
103
- setRequiredFlag(fn: boolean | ((result: Rule) => boolean)): void
104
-
105
- /**
106
- * This is the default-rule and will be overwritten by feature.setFlag() - rules.
107
- * In other words: If feature.setFlag == false, the result of the defaultRule applies.
108
- * @param fn DefaultRule
109
- */
110
- setDefaultFlag(fn: boolean | ((result: Rule) => boolean)): void
111
-
112
- addPlugin(plugin: Plugin)
113
- }
114
-
115
- type FeatureToggleApi = FeatureToggleApiBase & Record<string, any>;
116
-
117
- function parseToFn(fnOrBool: boolean | ((param?: any) => boolean)) {
118
- if (typeof fnOrBool == 'boolean')
119
- return function () { return fnOrBool };
120
-
121
- return fnOrBool;
122
- }
123
-
124
- function getKey(name: string, variant?: string): string {
125
- var _name = name.toLowerCase();
126
- if (variant && typeof variant == 'string') {
127
- _name += "#" + variant.toLowerCase();
128
- }
129
-
130
- return _name;
131
- }
132
-
133
- function initVisibilities(visibilities: FeatureToggleConfig = {}) {
134
- const returnVisibilities = {};
135
- Object.keys(visibilities).forEach(key => {
136
- if (key.startsWith('_') || key.startsWith('$'))
137
- return;
138
- returnVisibilities[getKey(key)] = parseToFn(visibilities[key]);
139
- });
140
- return returnVisibilities;
141
- }
142
-
143
- function useFeatureToggle(config: FeatureToggleConfig = {}): FeatureToggleApi {
144
-
145
- const globals = {
146
- datas: {},
147
- listeners: {},
148
- visibilities: initVisibilities(config),
149
- showLogs: false,
150
- usedPlugins: [],
151
- }
152
-
153
- function init(api: FeatureToggleApi) {
154
- if(config.$default){
155
- api.setDefaultFlag(config.$default);
156
- }
157
-
158
- if(config.$required){
159
- api.setRequiredFlag(config.$required);
160
- }
161
-
162
- const allPlugins = [...(config.$plugins||[]),...(config._plugins||[])];
163
- if(config._plugins){
164
- console.log('useFeatureToggle({_plugins:[]}): Key _plugins is deprecated. Use $plugins instead. This attribute will be removed in one of the next major versions.');
165
- }
166
-
167
-
168
- if (allPlugins.length) {
169
- allPlugins.forEach(plugin => {
170
- if (typeof plugin !== 'function')
171
- throw new Error('featuretoggleapi()-constructor: config.plugins needs functions as entries, not ' + typeof plugin + '.');
172
-
173
- api.addPlugin(plugin);
174
- });
175
- }
176
-
177
- triggerEvent('init');
178
- }
179
-
180
- function triggerEvent(eventtype: EventType, param?: any) {
181
- (globals.listeners[eventtype] || []).forEach(listener => {
182
- listener(param);
183
- });
184
- }
185
-
186
- const log = function (message) {
187
- if (!globals.showLogs)
188
- return;
189
-
190
- //Nur Browser können Syntaxhighlighting die anderen geben die Nachricht einfach aus und schneiden
191
- //die styletags raus
192
- if (typeof window === 'undefined') {
193
- const loggedMessage = message.replace(/<b>/g, "");
194
- console.log(loggedMessage);
195
- return;
196
- }
197
-
198
- var hasBoldTag = message.indexOf('<b>') != -1;
199
- var hasVisibleKeyword = message.indexOf('visible') != -1;
200
- var hasHiddenKeyword = message.indexOf('hidden') != -1;
201
-
202
- var _message = message.replace('visible', '%cvisible');
203
- _message = _message.replace('hidden', '%chidden');
204
-
205
- if (hasVisibleKeyword)
206
- console.log(_message, "color:green;font-weight:bold;");
207
- else if (hasHiddenKeyword)
208
- console.log(_message, "color:red;font-weight:bold;");
209
- else if (hasBoldTag) {
210
- _message = _message.replace('<b>', '%c');
211
- var parts = [_message, 'font-weight:bold;']
212
- console.log.apply(null, parts);
213
- }
214
- else
215
- console.log(message);
216
- }
217
-
218
- const logAndReturn = function (returnValue, message) {
219
- log(message);
220
- log('');
221
- return returnValue;
222
- }
223
-
224
- const getVisibility = function (visibilityFn, functionname, name, variant, data) {
225
- if (visibilityFn == null)
226
- return undefined;
227
-
228
- var calculatedVisibility = visibilityFn({ name: name, variant: variant, data: data });
229
-
230
- if (typeof calculatedVisibility == 'boolean') {
231
- return calculatedVisibility;
232
- }
233
-
234
- return logAndReturn(false, `The ${functionname} returns ${calculatedVisibility}. => Please return true or false. This result (and all non-boolean results) will return false.`);
235
- }
236
-
237
- function parseKey(key: string): OnEvent {
238
- const parts = key.split('#');
239
- return {
240
- name: parts[0],
241
- variant: parts.length > 1 ? parts[1] : undefined,
242
- data: globals.datas[key],
243
- }
244
- }
245
-
246
- /*
247
- the following calls are possible:
248
- visibility(name,result);
249
- visibility(name,variant,result);
250
- visibility(name,variant,data,result);
251
-
252
- =>
253
- param1: name
254
- param2: result || variant
255
- param3: result || data
256
- param4: result
257
- */
258
- function visibilityFnParams(param1, param2, param3, param4) {
259
- //name must always be set
260
- if (param1 == undefined)
261
- throw new Error('feature.visibility(): 1st parameter name must be defined');
262
-
263
- if (arguments.length == 1)
264
- throw new Error('feature.visibility(): 2nd parameter name must be a boolean or function, but is empty');
265
-
266
- let name = param1, variant = null, data = null, result = null;
267
- if (param3 == undefined && param4 == undefined) {
268
- result = param2;
269
- }
270
- else if (param4 == undefined) {
271
- variant = param2;
272
- result = param3;
273
- }
274
- else {
275
- variant = param2;
276
- data = param3;
277
- result = param4;
278
- }
279
-
280
- return {
281
- name,
282
- variant,
283
- data,
284
- result
285
- }
286
- }
287
-
288
- function getEvent(name: string, variant: string, data?, result?: any) {
289
-
290
- let event;
291
-
292
- event = { name, variant, data };
293
-
294
- event.key = getKey(event.name, event.variant);
295
-
296
- if (result == null)
297
- return event;
298
-
299
- event.visibilityFunction = parseToFn(result);
300
- event.result = event.visibilityFunction({
301
- name: event.name,
302
- variant: event.variant,
303
- data: event.data || {},
304
- _internalCall: true,
305
- description: 'When attaching a function, the result must be calculated internally. You can filter this out with the _internalCall:true -Flag.'
306
- })
307
- return event;
308
- }
309
-
310
-
311
-
312
- function isActive(name: string, variant?: string, data?: any): boolean {
313
- const visibilities = globals.visibilities;
314
-
315
- log(`\nCheck Visibility of <b>Feature "${name}", variant "${variant == undefined ? '' : variant}"${data ? " with data " + JSON.stringify(data) : ""}.`);
316
- if (name == undefined)
317
- throw new Error('The attribute "name" is required for tag <feature></feature>. Example: <feature name="aname"></feature>');
318
-
319
- var requiredFn = visibilities['_required'];
320
- var requiredFnExists = visibilities['_required'] != null;
321
- var requiredFnResult = getVisibility(requiredFn, 'requiredVisibility', name, variant, data);
322
-
323
- var visibilityFnKey = getKey(name, variant);
324
- var visibilityFn = visibilities[visibilityFnKey];
325
- var visibilityFnExists = visibilities[visibilityFnKey] != null;
326
- var visibilityFnResult = getVisibility(visibilityFn, 'visibility function', name, variant, data);
327
-
328
- var variantExists = variant != null;
329
- var visibilityOnlyNameFnKey = getKey(name, null);
330
- var visibilityOnlyNameFn = visibilities[visibilityOnlyNameFnKey];
331
- var visibilityOnlyNameFnExists = visibilities[visibilityOnlyNameFnKey] != null;
332
- var visibilityOnlyNameFnResult = getVisibility(visibilityOnlyNameFn, 'visibility function (only name)', name, variant, data);
333
-
334
- var defaultFn = visibilities['_default'];
335
- var defaultFnExists = visibilities['_default'] != null;
336
- var defaultFnResult = getVisibility(defaultFn, 'defaultVisibility', name, variant, data);
337
-
338
- if (!requiredFnExists)
339
- log("No requiredVisibility rule specified for this feature.");
340
- else if (requiredFnExists && requiredFnResult === true)
341
- log("The requiredVisibility rule returns true. This feature will be shown when no other rule rejects it.")
342
- else if (requiredFnExists && requiredFnResult === false)
343
- return logAndReturn(false, "The requiredVisibility rule returns false. This feature will be hidden.");
344
-
345
- if (visibilityFnExists)
346
- return logAndReturn(visibilityFnResult, `The visibility rule returns ${visibilityFnResult}. This feature will be ${visibilityFnResult ? 'visible' : 'hidden'}.`);
347
- log('No visibility rule found matching name and variant.');
348
-
349
- if (variantExists && typeof visibilityOnlyNameFnResult == 'boolean')
350
- return logAndReturn(visibilityOnlyNameFnResult, `Found a visibility rule for name ${name} without variants. The rule returns ${visibilityOnlyNameFnResult}. => This feature will be ${visibilityOnlyNameFnResult ? 'visible' : 'hidden'}.`);
351
- else if (variantExists)
352
- log(`No rules found for name ${name} without variants.`)
353
-
354
-
355
- if (defaultFnExists)
356
- return logAndReturn(defaultFnResult, `Found a defaultVisibility rule. The rule returns ${defaultFnResult}. => This feature will be ${defaultFnResult ? 'visible' : 'hidden'}.`);
357
- log(`No default rule found.`)
358
-
359
- if (requiredFnExists)
360
- return logAndReturn(true, `Only the requiredVisibility rule was found. This returned true. => This feature will be visible.`);
361
-
362
- return logAndReturn(false, 'No rules were found. This feature will be hidden.');
363
- }
364
-
365
- const api: FeatureToggleApi = {
366
- name: 'feature-toggle-api',
367
- setData: function (nameParam, variantOrDataParam, dataParam?): void {
368
- if (nameParam == undefined)
369
- throw new Error('setData(): The name must of the feature must be defined, but ist undefined');
370
-
371
- const variant = (dataParam != undefined ? variantOrDataParam : undefined) as string;
372
- const data = dataParam || variantOrDataParam;
373
-
374
- const event = getEvent(nameParam, variant, data);
375
-
376
- globals.datas[event.key] = event.data;
377
-
378
- triggerEvent('visibilityrule', event);
379
- },
380
- on(eventtype: EventType, fn, config?) {
381
- globals.listeners[eventtype] = globals.listeners[eventtype] || [];
382
- globals.listeners[eventtype].push(fn);
383
-
384
- triggerEvent('registerEvent', {
385
- type: eventtype
386
- })
387
- if (config != undefined && config.ignorePreviousRules)
388
- return;
389
-
390
-
391
- Object.keys(globals.visibilities).forEach(key => {
392
- const event = parseKey(key);
393
- const rule = globals.visibilities[key];
394
- event.result = rule(event);
395
- fn(event);
396
- });
397
- },
398
- trigger: triggerEvent,
399
- showLogs: function (showLogs?: boolean): void {
400
- globals.showLogs = showLogs == undefined ? true : showLogs;
401
- },
402
- isVisible(name,variant,data){
403
- console.log('featureToggle.isVisible is deprecated. use featureToggle.isActive instead. This function will be removed in one of the next major versions.');
404
- return isActive(name,variant,data);
405
- },
406
- isActive,
407
- /**
408
- the following function calls are possible:
409
- visibility(name,result);
410
- visibility(name,variant,result);
411
- visibility(name,variant,data,result);
412
- */
413
- setFlag(name, resultOrVariant, resultOrData?, result?) {
414
- const params = visibilityFnParams(name, resultOrVariant, resultOrData, result);
415
- const event = getEvent(params.name, params.variant, params.data, params.result);
416
-
417
- globals.visibilities[event.key] = event.visibilityFunction;
418
- globals.datas[event.key] = event.data;
419
- triggerEvent('visibilityrule', event);
420
- },
421
- visibility: function (name, resultOrVariant, resultOrData?, result?) {
422
- console.log('featureToggle.visibility is deprecated. use featureToggle.setVisibility instead. This function will be removed in one of the next major versions.');
423
-
424
- api.setFlag(name, resultOrVariant, resultOrData, result);
425
- },
426
- requiredVisibility: function (fn) {
427
- console.log('featureToggle.requiredVisibility is deprecated. use featureToggle.setRequiredFlag instead. This function will be removed in one of the next major versions.');
428
-
429
- api.setRequiredFlag(fn);
430
- },
431
- defaultVisibility: function (fn) {
432
- console.log('featureToggle.requiredVisibility is deprecated. use featureToggle.setRequiredFlag instead. This function will be removed in one of the next major versions.');
433
-
434
- api.setDefaultFlag(fn);
435
- },
436
- setRequiredFlag(fn) {
437
- if (typeof fn != "function")
438
- throw new Error('feature.setRequiredFlag(): 1st parameter must be a function, but is ' + typeof fn);
439
-
440
- globals.visibilities['_required'] = parseToFn(fn);
441
- },
442
- setDefaultFlag(fn) {
443
- if (typeof fn != "function")
444
- throw new Error('feature.defaultVisibility(): 1st parameter must be a function, but is ' + typeof fn);
445
-
446
- globals.visibilities['_default'] = parseToFn(fn);
447
- },
448
- addPlugin: function (plugin) {
449
- if (globals.usedPlugins.includes(plugin))
450
- return;
451
-
452
- const newPlugin = plugin(api);
453
-
454
- for(let _key of Object.keys(newPlugin)){
455
- api[_key] = newPlugin[_key];
456
- }
457
-
458
- globals.usedPlugins.push(plugin);
459
- },
460
- };
461
- init(api);
462
-
463
- return api;
464
- }
465
-
466
- export default useFeatureToggle;
package/src/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import { urlPlugin } from "./plugins/urlplugin/plugin-url"
2
- import { htmlPlugin } from "./plugins/htmlplugin/plugin-html"
3
- import useFeatureToggle from "./featureToggle"
4
-
5
-
6
- export {
7
- useFeatureToggle,
8
- urlPlugin,
9
- htmlPlugin
10
- }
@@ -1,83 +0,0 @@
1
- type Display = 'block' | 'inline-block' | 'inline' | 'flex' | 'inline-flex' | 'grid' | 'inline-grid';
2
-
3
- interface HtmlPluginConfig {
4
- renderedTag?: string,
5
- featureTagName?: string,
6
- tagAttributeName?: string,
7
- nameAttributeName?:string,
8
- variantAttributeName?: string,
9
- dataAttributeName?: string,
10
- displayAttributeName?: string,
11
- defaultDisplay?: Display,
12
- }
13
-
14
- /*
15
- creates a tag that is shown / hidden, depending on the visibility rules.
16
- if not configured dynamically, it looks like this:
17
- <feature name="featurename" variant="variantname" data="data">content </feature>
18
-
19
- Parameter: (config)
20
- - config.featureTagName: name of the tag. Default: "feature"
21
- - nameAttributeName: Name of the Name-Attribute: default: "name"
22
- - variantAttributeName: Name of the Variant-Attribute: default: "variant"
23
- */
24
- const defaultparams :HtmlPluginConfig = {
25
- renderedTag: 'div',
26
- featureTagName: 'feature',
27
- tagAttributeName: 'tag',
28
- nameAttributeName:'name',
29
- variantAttributeName: 'variant',
30
- dataAttributeName: 'data',
31
- displayAttributeName: 'display',
32
- defaultDisplay: 'block',
33
- }
34
- function parseDataAttribute(attrAsString){
35
- try{
36
- return JSON.parse(attrAsString);
37
- }
38
- catch(e)
39
- {
40
- if(!isNaN(parseFloat(attrAsString)))
41
- return parseFloat(attrAsString);
42
-
43
- return attrAsString;
44
- }
45
- }
46
-
47
- function htmlPlugin(config :HtmlPluginConfig = {}) {
48
- config = Object.assign({},defaultparams,config);
49
-
50
- function renderFeatureTag(elem:HTMLElement,isVisible){
51
- const tagname = elem.getAttribute(config.tagAttributeName) || config.renderedTag;
52
- const attributes = Array.from(elem.attributes);
53
- let attributesAsString = "";
54
- attributes.forEach(attr => {
55
- attributesAsString += ` ${attr.nodeName}="${attr.nodeValue.replace(/"/g,"&quot;")}"`;
56
- });
57
- const display = isVisible ? (elem.getAttribute(config.displayAttributeName) || config.defaultDisplay) : 'none';
58
- elem.outerHTML = `<${tagname} style="display:${display}" _feature="true" ${attributesAsString}>${elem.innerHTML}</${tagname}>`;
59
- }
60
- return function (api) {
61
- var renderedTags :NodeListOf<HTMLElement> = window.document.querySelectorAll(config.featureTagName);
62
- renderedTags.forEach(tag => { renderFeatureTag(tag,false) });
63
-
64
- api.on('visibilityrule', function (event) {
65
- var selector = `[_feature][${config.nameAttributeName}="${event.name}"]`;
66
- if (event.variant) selector += `[${config.variantAttributeName}="${event.variant}"]`;
67
- var elements :NodeListOf<HTMLElement> = document.querySelectorAll(selector);
68
- elements.forEach(elem => {
69
- const dataAsString = elem.getAttribute(config.dataAttributeName);
70
- const data = parseDataAttribute(dataAsString);
71
-
72
- const isVisible = api.isVisible(event.name,event.variant,data);
73
- renderFeatureTag(elem, isVisible);
74
- });
75
- })
76
-
77
- return { name: 'htmlplugin' };
78
- }
79
- }
80
-
81
- export {
82
- htmlPlugin
83
- }